PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
// Connect to database using the new and improved mysqli
$dbLink = new mysqli('localhost', 'user', 'password', 'database');
if(!$dbLink) {echo 'connection error';}
//query db system
$query ="select * from tbl_debug";
$result = $dbLink->query($query);
//test to see if results were returned
$num_results=$result->num_rows;
$count=1;
if ($num_results > 0) {
for($i=0; $i <$num_results; $i++) {
$row=$result->fetch_assoc();
echo 'Title row: '.$row['debug_Title'];
echo $count;
$count++;
}
}
echo 'test script ';
// garbage collection
if ($result <> null) {
$result->free();
$dbLink->close();
}
?>
it is the fetch_assoc that does not work. If I remove that I get a page with an echo of test script but If i have the fetch_assoc in then i get a page cannot be found in internet explorer and a no data found in firefox.
If I use the following code which makes use of the mysql extension then i get my results from the databae. However I have checked with phpinfo() and there is mysqli extension on the server. Also I can connect to the database using the mysqli connection string, so where can the error be i am totally confused.
I am using mysql version 4.1.11 database bcoz mysqli says it works with mysql version 4.1 and upwards and php5 and this is on a debian server.
But im thinking if mysqli did not work it would refuse me a connection to the database(wouldnt it). Also I do get a result when I ask it how many records are in the resultset and it gives me a number 15 . I followed your suggestion of the var_dump.
Sorry to be a pain but im desperate!
The mysql extension and mysqli extension from phpinfo dump is below
mysql
===============================================
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 4.0.24
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /var/run/mysqld/mysqld.sock
MYSQL_INCLUDE -I/usr/include/mysql
MYSQL_LIBS -L/usr/lib -lmysqlclient
Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode Off Off
===============================================
mysqli
===============================================
MysqlI Support enabled
Client API version 4.0.24
MYSQLI_SOCKET /var/run/mysqld/mysqld.sock
Directive Local Value Master Value
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket no value no value
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.reconnect Off Off
===============================================