fetch_assoc() function does not work when uploaded to Debian

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!

Moderator: General Moderators

Post Reply
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

fetch_assoc() function does not work when uploaded to Debian

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

doesn't work how? any error messages? (make sure to check your error_log file...
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

Post 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

Code: Select all

tags.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe you're not getting back a result object?

var_dump() $result.
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

Post 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();
		}
?>
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

Post 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) { }
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

Post by Antek_Ryu »

Any ideas?
Post Reply