Jump to content
Updating IPB tonight Read more... ×


This topic is now archived and is closed to further replies.


Need help connecting to mysql

Recommended Posts


I am new to php and mysql.
I have installed apache, php5, mysql 4.something.
I want to use localhost for developing and testing things locally

here 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.


// 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 database
mysql_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 returned
if (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 memory

// close connection


Thank you in advance


Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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 server
so the script (code) errors are outputted.

Share this post

Link to post
Share on other sites
If you are using php5, create a file called phpinfo.php:
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.php

Scroll 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.

Share this post

Link to post
Share on other sites
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";



Share this post

Link to post
Share on other sites


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.