coderb Posted February 20, 2008 Share Posted February 20, 2008 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, Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 20, 2008 Share Posted February 20, 2008 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>'); Quote Link to comment Share on other sites More sharing options...
coderb Posted February 20, 2008 Author Share Posted February 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
Guardian-Mage Posted February 21, 2008 Share Posted February 21, 2008 Dumb question, but have you looked through the phpinfo() page to see if MySQL is there? Quote Link to comment Share on other sites More sharing options...
coderb Posted February 21, 2008 Author Share Posted February 21, 2008 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 Quote Link to comment Share on other sites More sharing options...
coderb Posted February 22, 2008 Author Share Posted February 22, 2008 Anyone got any ideas on why I can't connect? Are there other checks I can do? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 22, 2008 Share Posted February 22, 2008 See if the following tip on this site sorts your problem out. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.