Differences between phpMyAdmin & mysql_connect function

Posted on 2004-08-31
Last Modified: 2010-05-18
I am having problems with my host allowing PHP to connect to MySQL and I've got one question.

I have insttalled phpMyAdmin and gotten it to connect to my database but I am unable to connect using mysql_connect as it says the function is undefined.  I would appreciate any documentation about how phpMyAdmin connects if my host is not willing to enable MySQL in the php.ini file.  Would also like to know how to connect via PHP other ways.

"Call to undefined function: mysql_connect() "

Using this code


$DB = mysql_connect('localhost','user','pass')or die("Connect Error: ".mysql_error());
mysql_select_db("mydb" , $DB) or die("Select DB Error: ".mysql_error());

Question by:f0rdmstang
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 14

Accepted Solution

ThG earned 50 total points
ID: 11948411
this sounds weird
try adding

before your mysql_connect() code.. (use mysql.dll instead if you are on win32)

Author Comment

ID: 11948988
Thanks ThC  that did help.  Now I'm getting this.

Warning: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/.sites/148/site6/web/norwood/test/flyer2/admin/includes/dbconnect.php on line 11

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/.sites/148/site6/web/norwood/test/flyer2/admin/includes/dbconnect.php on line 11
Connect Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I've looked over the net and only found something about restarting or killing MySQL then restarting.  let me know if you have any more ideas and I'll just have to wait till tomorrow when my host can restart the process.
LVL 11

Expert Comment

ID: 11950979
It appears as if your host is not running MySQL, or it is running but not on the standard ports.

I suggest contacting them to check that your account does have MySQL (I assume it does if you say phpMyAdmin works) and and their server is running on the standard ports or not.
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 11957417
My ISP gave me this info.  How do I specify the correct socket address or use this info to get my mysql_connect working ?

Yes, mysql is enabled in php.ini, but the PHP is not the newest, with
the version included on XXXXX is 4.0.6. PEAR was not included
by default in this version, although the XXXXX does have most of these
components installed.

That second link appears to be accessing MySQL through the UNIX socket
at /tmp/mysql.sock, when it is really /var/lib/mysql/mysql.sock.
LVL 11

Expert Comment

ID: 11961821
This is an issue that your ISP will need to resolve. It's not coding or anything.

To prove/disprove the above, install mysql onto your local computer, then try to use the command-line tool to connect using their IP and the user/password supplied.

mysql -h <ip> -u USERNAME -pPASSWORD

if this connects then it SHOULD work, if not then I'd get back to your provider with copies of your error messages...

Author Comment

ID: 11963112

Wasn't an ISP fix but rather that the ISP does have it setup right I'd think.  When I contacted ISP they gave me the sock path and I can't remember where I found the weird little '' line but I found it none the less.

$DB = mysql_connect('','user','pass')or die("Connect Error: ".mysql_error());
mysql_select_db("DBname" , $DB) or die("Select DB Error: ".mysql_error());



Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question