cescentman
asked on
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\in stantclien t10\sdk,sh ared"
"--with-oci8=C:\php-sdk\or acle\insta ntclient10 \sdk,share d"
"--with-oci8-11g=C:\php-sd k\oracle\i nstantclie nt11\sdk,s hared"
"--with-enchant=shared" "--enable-object-out-dir=. ./obj/"
"--enable-com-dotnet=share d" "--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:-
I would be grateful in help identifying how to progress this.
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
"--with-oci8=C:\php-sdk\or
"--with-oci8-11g=C:\php-sd
"--with-enchant=shared" "--enable-object-out-dir=.
"--enable-com-dotnet=share
"--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;';
I would be grateful in help identifying how to progress this.
You are i586, then you have to choose x86, 32-bit.
ASKER
Even though it's a 64bit operating system? Is the DSN unconnected with the MySQL connector then?
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.
ASKER
Thanks Dave
Any thoughts on the connection string I should be using?
Any thoughts on the connection string I should be using?
OOP:
Traditional PHP:
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;
}
}
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);
?>
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.
ASKER
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)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Dave, I'll look at this. Will be a few days but will get back to you.
ASKER
Works a treat I can see now I was trying to add an unnecessary layer. Thanks
You're welcome, glad to help.