Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1081
  • Last Modified:

Differences between phpMyAdmin & mysql_connect function

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());

?>
0
f0rdmstang
Asked:
f0rdmstang
  • 3
  • 2
1 Solution
 
ThGCommented:
this sounds weird
try adding
@dl("mysql.so");

before your mysql_connect() code.. (use mysql.dll instead if you are on win32)
0
 
f0rdmstangAuthor Commented:
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.
0
 
BrianMMCommented:
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.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
f0rdmstangAuthor Commented:
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.
0
 
BrianMMCommented:
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...
0
 
f0rdmstangAuthor Commented:
FIXED :)

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 '127.0.0.1:3306/var/lib/mysql/mysql.sock' line but I found it none the less.

<?
@dl("mysql.so");
$DB = mysql_connect('127.0.0.1:3306/var/lib/mysql/mysql.sock','user','pass')or die("Connect Error: ".mysql_error());
mysql_select_db("DBname" , $DB) or die("Select DB Error: ".mysql_error());

?>

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now