unable to connect to MySQL through odbc_connect()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
purusothaman
Forum Newbie
Posts: 5
Joined: Tue Feb 09, 2010 7:51 am

unable to connect to MySQL through odbc_connect()

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: unable to connect to MySQL through odbc_connect()

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
purusothaman
Forum Newbie
Posts: 5
Joined: Tue Feb 09, 2010 7:51 am

Re: unable to connect to MySQL through odbc_connect()

Post by purusothaman »

Now I am able to connect to MySQL thru ODBC api.

Thanks.
Post Reply