bluethundr Posted October 25, 2009 Share Posted October 25, 2009 Hey guys, Just familiarizing myself with PHP and MySQL. I am following along in the O'Reilly book that addresses both topics and has the platypus on the cover. At any rate, I tried typing in chapter 6 exercise 1 and the script did not work. I then downloaded the example code from the books website and found out what I typed was identical and actually tried the downloaded script and had THAT not work. Other PHP scripts are working, so I know it's not the system. For instance phpinfo.php does it's thing, as do my other scripts so far. Here is the code from the downloaded example: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Wines</title> </head> <body> <pre> <?php // (1) Open the database connection $connection = mysql_connect("localhost","fred","shhh"); // (2) Select the winestore database mysql_select_db("winestore", $connection); // (3) Run the query on the winestore through the connection $result = mysql_query ("SELECT * FROM wine", $connection); // (4) While there are still rows in the result set, fetch the current // row into the array $row while ($row = mysql_fetch_array($result, MYSQL_NUM)) { // (5) Print out each element in $row, that is, print the values of // the attributes foreach ($row as $attribute) print "{$attribute} "; // Print a carriage return to neaten the output print "\n"; } ?> </pre> </body> </html> I am running a Mac OS X 10.6 (Snow Leopard) system and have put the script in the same place that my other PHP scripts are working : Mac HD -> Library -> WebServer -> Documents This simple script is meant to access a MySQL db and print it's contents in a web browser. Obviously the db login here is fake. But in the 'real' script I have tried a user that should have rights and even tried it with root which I KNOW has rights. I am able to access the db from the command line interpreter using both the user and with root. The script and the browser are running locally on my machine and being served by apache (which has been restarted both with apachectl and with the GUI tools). Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/178951-solved-simple-mysql-script-is-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 25, 2009 Share Posted October 25, 2009 Are you developing and debugging php code in a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to help you by displaying all the errors it detects? (Stop and start your web server to get any change made to php.ini to take effect and confirm the actual settings using a phpinfo(); statement in case the php.ini that you are changing is not the one that php is using.) Quote Link to comment https://forums.phpfreaks.com/topic/178951-solved-simple-mysql-script-is-not-working/#findComment-944127 Share on other sites More sharing options...
bluethundr Posted October 25, 2009 Author Share Posted October 25, 2009 Are you developing and debugging php code in a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to help you by displaying all the errors it detects? (Stop and start your web server to get any change made to php.ini to take effect and confirm the actual settings using a phpinfo(); statement in case the php.ini that you are changing is not the one that php is using.) Ok! Thanks! I added both to my ini file and everything automagically works! Should they have been there all along? Do I need those statements in my php.ini file for normal operation or does that fact that the script only works with those statements in the php.ini file indicate that there is some problem of which I should be aware? Quote Link to comment https://forums.phpfreaks.com/topic/178951-solved-simple-mysql-script-is-not-working/#findComment-944199 Share on other sites More sharing options...
PFMaBiSmAd Posted October 25, 2009 Share Posted October 25, 2009 Setting those would have only caused php detected errors to be displayed. It is highly likely that your mysql extension was not enabled, producing fatal runtime errors, but because the error_reporting/display_errors were not set to show you the resulting errors, you were not receiving any feedback. I suspect that restarting the web server to enable those two settings that it likely enabled the mysql extension at the same time. Those two settings should be as indicated on every development system. They will save you a ton of time while learning php, developing php code, and debugging php code. Quote Link to comment https://forums.phpfreaks.com/topic/178951-solved-simple-mysql-script-is-not-working/#findComment-944311 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.