MySQL Connection Strings

I have a 2008 R2 server wit, MySQL 5.6.14 installed on it. I am running IIS and have PHP installed, phpinfo() gives me:-

PHP Version 5.3.24

System       Windows NT CURR-SERVER 6.1 build 7601 (Windows Server 2008 R2
Standard Edition Service Pack 1) i586
Compiler       MSVC9 (Visual C++ 2008)
Configure Command       cscript /nologo configure.js
"--enable-snapshot-build" "--enable-debug-pack" "--disable-zts"
"--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql"
"--without-pi3web"
"--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared"
"--with-enchant=shared" "--enable-object-out-dir=../obj/"
"--enable-com-dotnet=shared" "--with-mcrypt=static"
"--disable-static-analyze"

I have downloaded and installed the MySQL Connector from here:-

http://dev.mysql.com/downloads/connector/odbc/

... I chose: Windows (x86, 64-bit), MSI Installer

In Data sources I can see MySQL ODBC 5.3 Unicode Driver. I can create a DSN in data sources with tests fine

I am trying to connect my PHP code to MySQL. I have tried the following connection strings without success:-

$strCon = 'Driver={MySQL ODBC 5.3 Unicode Driver};Server=localhost;Database=' . $myDataBase . ';User=' .  $myUsername . ';Password=' .  $myPassword . ';Option=3;';
$strCon = 'Provider=MSDASQL;Driver={MySQL ODBC 5.3 Unicode Driver};Server=localhost;Database=' . $myDataBase . ';User=' .  $myUsername . ';Password=' .  $myPassword . ';Option=3;';
$strCon = 'Driver={MySQL ODBC 5.3 Unicode Driver};Server=localhost;Database=' . $myDataBase . ';User=' .  $myUsername . ';Password=' .  $myPassword . ';Option=3;';

Open in new window


I would be grateful in help identifying how to progress this.
LVL 1
cescentmanAsked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
Even with PDO, the builtin "pdo_mysql" MySQL driver is recommended (php_pdo_mysql.dll).  http://php.net/manual/en/ref.pdo-mysql.connection.php    If you run phpinfo(), you can see whether 'pdo_mysql' is enabled.  If not, edit 'php.ini' to enable it and restart the server.   On the other hand, the ODBC driver adds another layer but it should work if that's what you want.
0
 
Mohamed MagdyCTOCommented:
You are i586, then you have to choose x86, 32-bit.
0
 
cescentmanAuthor Commented:
Even though it's a 64bit operating system? Is the DSN unconnected with the MySQL connector then?
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
Dave BaldwinFixer of ProblemsCommented:
Since you have PHP, you should use the MySQL drivers for PHP.  http://php.net/manual/en/book.mysqli.php  You don't need the MySQL Connector for PHP though you might find it useful for other languages.
0
 
cescentmanAuthor Commented:
Thanks Dave

Any thoughts on the connection string I should be using?
0
 
Mohamed MagdyCTOCommented:
OOP:

private db_host = ‘’; 
private db_user = ‘’; 
private db_pass = ‘’; 
private db_name = ‘’; 
 
public function connect()
    {
        if(!$this->con)
        {
            $myconn = @mysql_connect($this->db_host,$this->db_user,$this->db_pass);
            if($myconn)
            {
                $seldb = @mysql_select_db($this->db_name,$myconn);
                if($seldb)
                {
                    $this->con = true; 
                    return true; 
                } else
                {
                    return false; 
                }
            } else
            {
                return false; 
            }
        } else
        {
            return true; 
        }
    }

Open in new window


Traditional PHP:

<?php

//ENTER YOUR DATABASE CONNECTION INFO BELOW:
$hostname="HOSTNAME";
$database="DBNAME";
$username="DBUSER";
$password="myPassword";

//DO NOT EDIT BELOW THIS LINE
$link = mysql_connect($hostname, $username, $password);
if (!$link) {
die('Connection failed: ' . mysql_error());
}
else{
     echo "Connection to MySQL server " .$hostname . " successful!
" . PHP_EOL;
}

$db_selected = mysql_select_db($database, $link);
if (!$db_selected) {
    die ('Can\'t select database: ' . mysql_error());
}
else {
    echo 'Database ' . $database . ' successfully selected!';
}

mysql_close($link);

?>

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
You can't use the code above because the 'mysql' functions are obsolete http://php.net/manual/en/intro.mysql.php .  Please read the articles I linked about 'mysqli' which is the current MySQL driver.   This page http://php.net/manual/en/mysqli.construct.php shows you where to start.  You won't be using connection strings like you would in MS SQL server.
0
 
cescentmanAuthor Commented:
I'm using PDO:-

$strCon = 'Driver={MySQL ODBC 5.3 Unicode Driver};Server=localhost;Database=' . $myDataBase . ';User=' .  $myUsername . ';Password=' .  $myPassword . ';Option=3;';
    $objThumbs = new PDO($strCon)

Open in new window

0
 
cescentmanAuthor Commented:
Thanks Dave, I'll look at this. Will be a few days but will get back to you.
0
 
cescentmanAuthor Commented:
Works a treat I can see now I was trying to add an unnecessary layer. Thanks
0
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.