Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Differences between phpMyAdmin & mysql_connect function

Posted on 2004-08-31
6
Medium Priority
?
1,075 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 200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

877 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