Mysqli query fetching no records

CoderRoller

I am trying to run a PHP script that uses mysqli library, but it fetches no results on the webhosting server while in my machine running WLAMP PHP 5.14 it works well.

Can you please tell me if the problem is related with mysqli and if there is a way to make it work for my case?.

The lines I am looking to make work look like this:

$sql = "call sp_give_me_data(null,null,null);";

if (!$mysqli->query($sql)) {
   die('Invalid query: ' . mysql_error());
} else {

   $result = $mysqli->query($sql);

   if ($result->num_rows > 0) {
     while($row = $result->fetch_assoc()) {
       $datainfo[] = $row;
     }
     $output = json_encode($datainfo);
     echo utf8_encode($output);    
   } else {
     echo "0";
   }

}

as I said it fetches "0" records on the hosting which supports PHP 5.3-5.5 and it fetches the correct number of records on my machine. The connection to the remote database (which is the same in both cases) seems successful as well.

Thanks for the insight.

Update

I changed my code so now I am sending the query just once:

mysqli_set_charset($mysqli,"utf8"); //utf-8 accents query
$result = $mysqli->query($sql);     

if (!$result) {     
    die('Invalid query: ' . mysql_error());
} else {

    if ($result->num_rows > 0) {            
        while($row = $result->fetch_assoc()) {              
            $datainfo[] = $row;
        }
        //utf-8 accents unescaping to be shown correctly
        $output = json_encode($datainfo,JSON_UNESCAPED_UNICODE);
        echo $output;                       

    } else {
        echo "0";
    }       
}

This works now. Thx!

CoderRoller

With the suggestion of @VolkerK, this works now:

mysqli_set_charset($mysqli,"utf8"); //utf-8 accents query
$result = $mysqli->query($sql);     

if (!$result) {     
    die('Invalid query: ' . mysql_error());
} else {

    if ($result->num_rows > 0) {            
        while($row = $result->fetch_assoc()) {              
            $datainfo[] = $row;
        }
        //utf-8 accents unescaping to be shown correctly
        $output = json_encode($datainfo,JSON_UNESCAPED_UNICODE);
        echo $output;                       

    } else {
        echo "0";
    }       
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Postgresql query for fetching records

From Dev

Fetching CloudKit Records By Name and Query in PHP

From Dev

Query Response for fetching receive payment records from quickbooks db?

From Dev

mysqli fetch() not fetching

From Dev

mysqli insertion query neither insert records nor shows the location of error

From Dev

Error in fetching records in angularjs

From Dev

Laravel : Fetching records with condition

From Dev

Fetching 1000 + records quikly

From Dev

DB2 Query for fetching records from first query, if first query fails, then fetch from 2nd query

From Dev

Query for fetching mismatching records from a table by cross checking with 2 other tables

From Dev

Fetching crossed records from database

From Dev

mysql reverse order of records fetching

From Dev

mysql reverse order of records fetching

From Dev

Fetching all records Through PDO

From Dev

Fetching Firebase Records Based on Email

From Dev

PDO error while fetching records

From Dev

Fetching records from Cust table

From Dev

Query in MongoDb for fetching record

From Dev

Issue with fetching query

From Dev

Undefined variable while fetching data from mysqli

From Dev

fetching the data when using prepared statements with mysqli

From Dev

Error fetching mysqli results using mysqli fetch assoc()

From Dev

MYSQLi Multiple Records Outputs Duplicates

From Dev

MySQL: Fetching circular records in SELECT statement

From Dev

fetching number of records from outer join table

From Dev

Logic is not clear while fetching records from DB

From Dev

Ember Data is always fetching records for route

From Dev

Fetching Records to a Select Menu with a Section Header

From Dev

Fetching records of employee hired in specfic month

Related Related

HotTag

Archive