Page 1 of 1
fetch_assoc() function does not work when uploaded to Debian
Posted: Tue Aug 09, 2005 11:02 am
by Antek_Ryu
Hi
I am new to this forum and I am having some major problems with some code. I wrote some php pages and they work fine on my windows machine but when I upload them to my host which is Debian Linux. The following function does not work fetch_assoc();
I am posting the code below
I am using php5, mysql 4.1 and mysqli extension
Pllleeeeeaseee can someone help!!!!!!
PLEEAASSEE
Code: Select all
<?php
$mysqli = new mysqli("host", "username", "password", "database");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT * from tbl_debug";
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
printf("%s (%s)\n", $row["debug_ID"], $row["debug_Name"]);
}
/* free result set */
$result->close();
}
/* close connection */
$mysqli->close();
?>
feyd | welcome to the forums, please use Code: Select all
tags when posting php code.[/color]
Posted: Tue Aug 09, 2005 11:35 am
by feyd
doesn't work how? any error messages? (make sure to check your error_log file...
Posted: Tue Aug 09, 2005 11:51 am
by Antek_Ryu
How can i check the error log? the hosting company i think will not allow me to do this.
I dont get no errors all it says page not found, if i take out the fetch_assoc it will work for example if i try to delete from the database. I am so stuck (:-<).
I have also disabled windows friendly error messages so i could see some errors but it does not work
if i try the older style coding then it does return results but i have completed my whole project in php5 object orientated style
Code: Select all
<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'user', 'password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('database') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM tbl_debug';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
mysql_free_result($result);
// Closing connection
mysql_close($link);
?>
Any ideas ?
PLEASE
feyd | seriously.. please start using
Posted: Tue Aug 09, 2005 12:00 pm
by feyd
maybe you're not getting back a result object?
var_dump() $result.
Posted: Tue Aug 09, 2005 12:19 pm
by Antek_Ryu
Hi feyd
Thankyou for helping me, the code below is the exact code im using in my project. I put in a counter to see if it returns a resultset and my counter counts 15 times. This is the number of rows in my table, so i presume it is getting a resultset. Can their be any sort of php.ini file configuration the administering host might need to do?
Is fetch_assoc part of php4 aswell? Can it be fetch_assoc library is not present?
How can I test for these?
Code: Select all
<?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();
}
?>
Posted: Tue Aug 09, 2005 1:00 pm
by Antek_Ryu
I did a code dump as you suggested and i get the following output. I cant understand what it is telling me. but it seems to be empty, am i correct? why would this be.
code]object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { } object(mysqli_result)#2 (0) { }
Posted: Tue Aug 09, 2005 2:56 pm
by Antek_Ryu
Any ideas?