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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connection issue

Status
Not open for further replies.

Shadow2097

Programmer
Joined
Aug 9, 2001
Messages
2
Location
US
Hi all,

I'm not sure if this is a MySQL problem or a PHP problem, but I'm going to start here. I'm trying to run a simple database query that will display the results in an HTML table. Unfortunately, I can't get the script to get past the mysql_connect() function. Here's relevant parts of the script:
<code>
<?php
//connect to server, then test for failure
if(!($dbLink = mysql_connect(&quot;localhost&quot;,&quot;<changed for security>&quot;,&quot;<changed for security>&quot;)))
{
print(&quot;Failed to connect to database!<br>\n&quot;);
print(&quot;Aborting!<br>\n&quot;);
exit();
}

//select database, then test for failure
if(!($dbResult = mysql_query(&quot;USE shadow&quot;,$dbLink)))
{
print(&quot;Can't use 'shadow' database!<br>&quot;);
print(&quot;Aboring!<br>&quot;);
exit();
}

//select everything from the PERSON table
$Query = &quot;SELECT * from PERSON &quot; .
&quot;ORDER BY NAME &quot;;

if(!($dbResult = mysql_query($Query,$dbLink)))
{
print(&quot;Couldn't execute query!<br>\n&quot;);
print(&quot;MySQL reports: &quot; . mysql_error() . &quot;<br>\n&quot;);
print(&quot;Query was: $Query<br>\n&quot;);
exit();
}
...
</code>
Everything else is just the HTML table building.

This is the output I get on the webpage:
<output>
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /usr/local/apache/htdocs/shadowrealm/db_test.php on line 3
Failed to connect to database!
Aborting!
</output>

Is there something I'm missing in my PHP or does this sound like a MySQL configuration issue?

Thanks,
-Shadow
 
You're not telling your script to give you explicit-enough error messages.

Change:
Code:
        if(!($dbLink = mysql_connect(&quot;localhost&quot;,&quot;<changed for security>&quot;,&quot;<changed for security>&quot;)))
        {
                print(&quot;Failed to connect to database!<br>\n&quot;);
                print(&quot;Aborting!<br>\n&quot;);
                exit();
        }

To read:

Code:
        if(!($dbLink = mysql_connect(&quot;localhost&quot;,&quot;<changed for security>&quot;,&quot;<changed for security>&quot;)))
        {
                die (mysql_error());
        }

Want the best answers? Ask the best questions: TANSTAAFL!!
 
is mysql running? It looks like mysql is not running.
(ps -ef|grep mysql)

2. you have:
Code:
if(!($dbResult = mysql_query(&quot;USE shadow&quot;,$dbLink)))
        {
                print(&quot;Can't use 'shadow' database!<br>&quot;);
                print(&quot;Aboring!<br>&quot;);
                exit();
        }

Use:
Code:
mysql_select_db(&quot;shadow&quot;) or die(&quot;Can't use 'shadow' database!<br>Aborting!<br>&quot;);

&quot;die&quot; is very usefull. You can have:
Code:
mysql_connect(&quot;localhost&quot;,&quot;<changed for security>&quot;,&quot;<changed for security>&quot;) or die (&quot;Failed to connect to database!<br>\n&quot;);
[CODE]

instead of &quot;if(!($db=mysql_connect(....&quot;.
Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top