Jump to content


Photo

Need to print contents of table...fetch error?


  • Please log in to reply
2 replies to this topic

#1 Conjurer

Conjurer
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 18 October 2006 - 07:00 PM

I am just looking for a simple way to test if my database is working. Wanted to get a listing of the contents of the user table from my bookmarks database but the code I am using generates the following errror message.

Fatal error: Call to a member function fetch_assoc() on a non-object in /home/consult/public_html/development/Testing/26/dbtest2.php5 on line 14


The code running in php5 is as follows:
<?php 
$mysqli = new mysqli('localhost',"consult_test", "password");
$mysqli->select_db("consult_bookmarks");

$result = $mysqli->query("SELECT * FROM users");

while($row = $result->fetch_assoc()) {
	print $row['username'] . ' ' . $row['passwd'].' ' . $row['email']. '<br/>';
}

$result->close();
?>

Are you guys sure this php stuff works!  j/k - just wish I knew what I was doing wrong. At least I got the parsing errors sorted!

#2 Conjurer

Conjurer
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 18 October 2006 - 08:06 PM

;D  OOPs!  Corrected the name of the table and now it works.



#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 19 October 2006 - 04:20 PM

You should always debug with mysql_error() so that you can catch MySQL-related syntax errors easily.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users