View Single Post
Old 01-18-2013, 06:27 AM   PM User | #1
epheterson
New Coder

 
Join Date: Nov 2007
Posts: 50
Thanks: 2
Thanked 0 Times in 0 Posts
epheterson is an unknown quantity at this point
Question Should be simple... echo count of rows in MySQL table

PHP Code:
<?php

$server
="localhost";
$user="user";
$password="password";
$database="database";

$db = new mysqli($server,$user,$password,$database);
if (
$db->connect_errno) {
printf("Connect failed: %s\n"$mysqli->connect_error);
exit();
}

$q 'SELECT COUNT(*) FROM example';
$r=mysqli_query($db,$q) or die(mysqli_error($db)." Q=".$q);
$r mysql_fetch_row($r);
echo 
$r[0];

?>
For the life of me, I cannot see why this returns 0, or print_r($db) -> empty SQL array
Code:
mysqli_result Object ( )
epheterson is offline   Reply With Quote