Solved

Differences between phpMyAdmin & mysql_connect function

Posted on 2004-08-31
6
1,047 Views
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());

?>
0
Comment
Question by:f0rdmstang
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
ThG earned 50 total points
ID: 11948411
this sounds weird
try adding
@dl("mysql.so");

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

Author Comment

by:f0rdmstang
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.
0
 
LVL 11

Expert Comment

by:BrianMM
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.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 1

Author Comment

by:f0rdmstang
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.
0
 
LVL 11

Expert Comment

by:BrianMM
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...
0
 
LVL 1

Author Comment

by:f0rdmstang
ID: 11963112
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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

777 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