Jump to content


Photo

Need help connecting to mysql


  • Please log in to reply
4 replies to this topic

#1 wolftone

wolftone
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 12 July 2006 - 11:51 PM

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

#2 mrome

mrome
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 13 July 2006 - 12:10 AM

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.

#3 CheesierAngel

CheesierAngel
  • Members
  • PipPipPip
  • Advanced Member
  • 105 posts
  • LocationBelgium

Posted 13 July 2006 - 09:21 AM

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.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 July 2006 - 02:14 PM

If you are using php5, create a file called phpinfo.php:
<?php
phpinfo();
?>
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 read this.

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.


#5 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 13 July 2006 - 02:41 PM

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users