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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.