cant get results

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

cant get results

Post by Antek_Ryu »

I am trying to run the following code but i cant get any results. I have done a code dump but nothing is being returned. Why is this happening?

If i do $num_results it returns 15 rows which is correct

If i run the code on my pc it works but when i upload this to my host it does not work.



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(); 
        } 
?>





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) { }
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Obvious questions first:
Does the database have the same field names on your online server?
Are you getting any errors?
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

If you remove the

Code: Select all

if ($num_results > 0) {
line does it work then?

(You don't really need this line, becuase if $num_results is 0 the the for loop will not run.)
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

Post by Antek_Ryu »

The database name is the same and the column is the one i want. I have taken the counter number out and it still does not work and more ideas,


Many thanks
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

Post by Antek_Ryu »

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.



The code below will work

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

Post by feyd »

why did you create a new thread for the same problem? :? impatience gets you nothing but a headache.

what exact version of mysql are you running? From what I remember, the mysql API and mysqli API didn't really mix too well on the same mysql server...
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

Post by Antek_Ryu »

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
===============================================
Post Reply