wolftone Posted July 12, 2006 Share Posted July 12, 2006 HiI am new to php and mysql.I have installed apache, php5, mysql 4.something.I want to use localhost for developing and testing things locallyhere is the script I am using, and all I get is a blank page...When I go to cmd console, I can access mysql and update and create and all of that good stuff. Please help.<?php// set database server access variables:$host = "localhost";$user = "root";$pass = "";$db = "test";// open connection$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");// select databasemysql_select_db($db) or die ("Unable to select database!");// create query$query = "SELECT * FROM test.groc_inventory";// execute query$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());// see if any rows were returnedif (mysql_num_rows($result) > 0) { // yes // print them one after another echo "<table cellpadding=10 border=1>"; while($row = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>".$row[0]."</td>"; echo "<td>" . $row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo "</tr>"; } echo "</table>";}else { // no // print status message echo "No rows found!";}// free result set memorymysql_free_result($result);// close connectionmysql_close($connection);?>Thank you in advanceMartin Quote Link to comment https://forums.phpfreaks.com/topic/14428-need-help-connecting-to-mysql/ Share on other sites More sharing options...
mrome Posted July 13, 2006 Share Posted July 13, 2006 I would download mysql 5.0.I'd use the new extension mysqi which is the improved extension.Finally I'd use mysqli_connect.Take a look at php.net and do some reading on mysqli and it's methods and properties. Quote Link to comment https://forums.phpfreaks.com/topic/14428-need-help-connecting-to-mysql/#findComment-57037 Share on other sites More sharing options...
CheesierAngel Posted July 13, 2006 Share Posted July 13, 2006 Maybe you need to adjust your apache conf file so the code errors are outputted.Some time ago i had the same problem, and i had to reconfigure my apache serverso the script (code) errors are outputted. Quote Link to comment https://forums.phpfreaks.com/topic/14428-need-help-connecting-to-mysql/#findComment-57170 Share on other sites More sharing options...
wildteen88 Posted July 13, 2006 Share Posted July 13, 2006 If you are using php5, create a file called phpinfo.php:[code]<?phpphpinfo();?>[/code]Now save this to the folder in which you have to put your php files in for the server to see them. then goto http://localhost/phpinfo.phpScroll down the page and see if there is a mysql section should be about 2/3 of the way down the page. If you dont see anything for mysql. Then you need to enable the mysql extension. To enable the extension please [url=http://www.phpfreaks.com/forums/index.php/topic,95378.0.html]read this[/url].Also I suggest you enable error reporting too, if you are developing your scripts locally.I will be moving this thread to the Installation forum. Quote Link to comment https://forums.phpfreaks.com/topic/14428-need-help-connecting-to-mysql/#findComment-57326 Share on other sites More sharing options...
craygo Posted July 13, 2006 Share Posted July 13, 2006 Is test.groc_inventory an actual table??If test is the database there is no need to include it in the query, you have alrady selected it on the connection. If groc_inventory is the table the query should be$query = "SELECT * FROM groc_inventory";LaterRay Quote Link to comment https://forums.phpfreaks.com/topic/14428-need-help-connecting-to-mysql/#findComment-57340 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.