Page 1 of 1

unable to connect to MySQL through odbc_connect()

Posted: Tue Feb 09, 2010 8:13 am
by purusothaman
Hi all,

While executing below PHP code I got display "MySQL Connect Error". I am not able to identify my mistake.
Pls help to successfully connect to my MySQL database.

Code: Select all

 $c = odbc_connect("root", "pass123", "Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Port=3306;Database=db1; User=root;Password=pass123;Options=3;");
  if ($c) {
   echo "Successfully connected to MySQL.";
   odbc_close($c);
 } 
 else {   
   echo "MySQL Connect Error ";
 }
 
Environement:
-------------
OS : Windows XP;
ODBC Driver : MySQL ODBC 5.1 Driver
Web Server : Apache
DB : MySQL.

Note : I am able to connect to the database thru VC++ using CDatabase(it uses same ODBC string)

Regards,
Purusothaman A

Re: unable to connect to MySQL through odbc_connect()

Posted: Tue Feb 09, 2010 9:46 am
by AbraCadaver
#1 There are specific functions for mysql, either the mysql_x() functions or the mysqli_x() functions.

#2 If you are tied to ODBC for whatever reason, you need to read the documentation for odbc_connect(). You are not using the correct order of parameters.

Re: unable to connect to MySQL through odbc_connect()

Posted: Tue Feb 09, 2010 11:08 pm
by purusothaman
Now I am able to connect to MySQL thru ODBC api.

Thanks.