f0rdmstang
asked on
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','pa ss')or die("Connect Error: ".mysql_error());
mysql_select_db("mydb" , $DB) or die("Select DB Error: ".mysql_error());
?>
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',
mysql_select_db("mydb" , $DB) or die("Select DB Error: ".mysql_error());
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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.
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.
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...
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...
ASKER
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/my sql/mysql. sock' line but I found it none the less.
<?
@dl("mysql.so");
$DB = mysql_connect('127.0.0.1:3 306/var/li b/mysql/my sql.sock', 'user','pa ss')or die("Connect Error: ".mysql_error());
mysql_select_db("DBname" , $DB) or die("Select DB Error: ".mysql_error());
?>
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/my
<?
@dl("mysql.so");
$DB = mysql_connect('127.0.0.1:3
mysql_select_db("DBname" , $DB) or die("Select DB Error: ".mysql_error());
?>
ASKER
Warning: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/.sites/148/site6/web
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/.sites/148/site6/web
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.