Jump to content

New PHP installation not connecting to MySQL database


Recommended Posts

Hi All,

 

I recently reinstalled OpenSuse 10.3 with PHP 5.2.5 and MySql 5.0.51, running on Apache 2.2.4.

 

I've copied a PHP application that was running on another machine, created it's database and restored it from a dump, and created the db user with privileges.

 

however, when I try to access the database from the PHP app, it does not perform the connect nor does it give any errors?

I've created this test page here to explain the issue, its just a drop down list that should be populated by the select statement.

 

The result here is simply an empty dropdownlist, no errors.

 

even if I stop the mysql server, or give it invalid sql syntax, I get the same result, so I gather it's just not even attempting to connect.

 

here is my code:

 

<?

 

$connection = mysql_connect("localhost", "user", "pwd");

mysql_select_db("db", $connection);

 

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>Deals</title>

</head>

<body>

<h2>Deals</h2>

<table>

<tr><td>

<select name="selDistributor" class=sixth>

<option value="0"> </option>

<?

$sqlDist = "select distributor_id, distributor_name from tblDistributors order by distributor_name";

$resDist = mysql_query($sqlDist, $connection);

while ($rowDist = mysql_fetch_row($resDist)) {

echo "<option value=".$rowDist[0];

if ($rowDist[0] == $_GET['selDistributor']) echo " selected";

echo ">".$rowDist[1]."</option>";

}

?>

</select>

</td>

</tr>

</table>

</body>

</html>

 

I've run the same select statment in mysql from the command prompt, and it works.

Is there some additional setting I should check in php.ini in order to access mysql from php, from what I've seen it looks okay.

 

Thanks for the help,

Link to comment
Share on other sites

In order for any errors to be shown when the code is being executed, make sure error_reporting is set to E_ALL and that display_errors is enabled within the php.ini. Also I would recommend you to change the following two lines:

$connection = mysql_connect("localhost", "user", "pwd");
mysql_select_db("db", $connection);

to:

$connection = mysql_connect("localhost", "user", "pwd") or die('MySQL Connection Failed! - ' . mysql_error());
mysql_select_db("db", $connection) or die(mysql_error());

 

and change the following line:

$resDist = mysql_query($sqlDist, $connection);

to:

$resDist = mysql_query($sqlDist, $connection) or die('Query Error: ' . mysql_error() . '<br /><pre>' . $sqlDist . '</pre>');

Link to comment
Share on other sites

hi,

thanks for the tips. I've changed the php.ini file and displays this error:

 

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13) in /srv/www/htdocs/adco/include/functions.php on line 15 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /srv/www/htdocs/adco/include/functions.php on line 16

 

So it is definitely a connection issue, however if I use the mysql command promt with the same user to run the select statement, I get the returned rows as expected. it just seems that thru php it's not connecting, any ideas?

 

 

thanks

Link to comment
Share on other sites

mysql

MySQL Support enabled

Active Persistent Links 0

Active Links 0

Client API version 5.0.51

MYSQL_MODULE_TYPE external

MYSQL_SOCKET /var/lib/mysql/mysql.sock

MYSQL_INCLUDE -I/usr/include/mysql

MYSQL_LIBS -L/usr/lib -lmysqlclient

 

Directive Local Value Master Value

mysql.allow_persistent Off Off

mysql.connect_timeout 60 60

mysql.default_host no value no value

mysql.default_password no value no value

mysql.default_port 3306 3306

mysql.default_socket no value no value

mysql.default_user no value no value

mysql.max_links Unlimited Unlimited

mysql.max_persistent Unlimited Unlimited

mysql.trace_mode On On

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.