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, Link to comment https://forums.phpfreaks.com/topic/92118-new-php-installation-not-connecting-to-mysql-database/ Share on other sites More sharing options...
Sulman Posted February 20, 2008 Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92118-new-php-installation-not-connecting-to-mysql-database/#findComment-471747 Share on other sites More sharing options...
coderb Posted February 20, 2008 Author Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92118-new-php-installation-not-connecting-to-mysql-database/#findComment-471877 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? Link to comment https://forums.phpfreaks.com/topic/92118-new-php-installation-not-connecting-to-mysql-database/#findComment-473292 Share on other sites More sharing options...
revraz Posted February 22, 2008 Share Posted February 22, 2008 Are you using root as the id and pw? Try root as the id and a blank pw. Link to comment https://forums.phpfreaks.com/topic/92118-new-php-installation-not-connecting-to-mysql-database/#findComment-473295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.