Jump to content

Recommended Posts

Hi

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.

<?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 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
mysql_free_result($result);

// close connection
mysql_close($connection);

?>

Thank you in advance

Martin
Link to comment
https://forums.phpfreaks.com/topic/14428-need-help-connecting-to-mysql/
Share on other sites

If you are using php5, create a file called phpinfo.php:
[code]<?php
phpinfo();
?>[/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.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.
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";

Later

Ray
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.