Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_connect

Status
Not open for further replies.

zackiv31

Programmer
May 25, 2006
148
US
I can't connect or get a response from the mysql_connect() operation. Running linux with apache and mysql

netstat -a | grep mysql
tcp 0 0 *:mysql *:* LISTEN
unix 2 [ ACC ] STREAM LISTENING 15374 /var/lib/mysql/mysql.sock


here's the code I'm trying to run:
<?php
$link = mysql_connect ("localhost:15374", "username", "pass")
or die ("Could not connect");
print ("Connected successfully");
mysql_close ($link);
?>

I have more complicated code, but it boils down to this and I can't connect.. is there another way for me to test my code outside of php? I don't know why it's not connecting..
 
Try this and see if you get some more info out of the mysql connection:

Code:
  $link = mysql_connect ("localhost:15374", "username", "pass")
        or die ([red]mysql_error()[/red]);

You could also try a front end like MYSQLQuery Browser, or something like that, to try to connect directly to mysql.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I dont know if I have logging enabled... where would these error messages be printing?

(doesn't look like it is working)
 
The fact that you see:

unix 2 [ ACC ] STREAM LISTENING 15374 /var/lib/mysql/mysql.sock

Doesn't mean MySQL is listening on port 15374. Unless you know for a fact MySQL is listening on a non-standard port, don't reference a port in your mysql_connect() invocation.

Code:
<?php
    $link = mysql_connect ("localhost", "username", "pass");
    if ($link !== FALSE)
    {
        print ("Connected successfully");
        mysql_close ($link);
    }
    else
    {
        print ("Did not connect:" . mysql_error());
    }
?>



Want the best answers? Ask the best questions! TANSTAAFL!
 
It should be printing on the web page that has that code in it. or if you are running it from a command prompt it should print it to screen.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Web page doesn't print anything...

It seems to get to the mysql_connect()... and quit executing...

The page stops loading, so I'm assuming it's done, but it doesn't get to any of the print statements...
 
Try changing your conditional test from

Code:
if ($link !== FALSE)

to

Code:
if ($link != FALSE)

I'm not sure that will make a big difference, but I'm also pretty sure that !== is not a PHP comparison operator.
 
jet042 said:
I'm not sure that will make a big difference, but I'm also pretty sure that !== is not a PHP comparison operator.

<<sigh>>

Yes, it is. Had you actually gone to (the PHP online manual page which talks about comparison operators), you would have found information on both the === and !== operators.



Want the best answers? Ask the best questions! TANSTAAFL!
 
While the information is appreciated, the attitude is not. I'm trying to help and I've made more simple errors than using an illegal operator before.
 
Sure, I've used illegal operators in my own code before.

But before I correct my fellow members in the fora, I make as sure as possible that my correction is accurate. Accuracy checking is extraordinarily easy with PHP because the language has such a exhaustive and well-organized online resource:


Want the best answers? Ask the best questions! TANSTAAFL!
 
zackiv31

going back to the start can you confirm that you have display errors and error_reporting set to On and E_ALL or higher respectively? if not, please change these settings and try again.

you can change the settings in php.ini (restart the webserver afterwards) or you may be able to change them programmatically by adding these lines at the start of your script

Code:
ini_set("display_errors", "on");
error_reporting(E_ALL);
 
I think I solved it by starting mysql server before apache webserver..

Don't know if you guys have used webmin, but how do I make these two autostart, and in the correct order?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top