Jump to content

New PHP installation not connecting to MySQL database


coderb

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

Put some error checking in there,

 

I would suggest starting with:

 

<?php
if(!mysql_select_db("db", $connection))
{
    die("Error:".mysql_error());
}
?>

 

This will tell us if there is a problem connecting to your database.

You can add the same checks to your other mysql queries to see what is happening.

e.g.

 

<?php
if(!mysql_query($sqlDist, $connection)
{
    die("Error:".mysql_error());
}
?>

etc..

Link to comment
Share on other sites

hi, thanks for the tip, I've instead set my php.ini - mysql.trace_mode = On.

 

I get 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/flow/mydbtest.php on line 3 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /srv/www/htdocs/adco/flow/mydbtest.php on line 4

 

I tried connecting using 'root' (which has access to all databases), but I get the same error.

Because this is a new install, perhaps I'm missing something in the config of mysql or php?

 

I know that mysql is running and since I have tested the same query on the mysql command line, using root login, not sure what the probelm is?

 

thanks

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.