Reputation: 79
I would want to return some information from a database. The Problem when the query is executed in MySQL it works fine but when I run the same Query in PHP , it does not work. It only works if I set a limit to less than 9. Any thing 9 and above returns a blank screen. My table currently has over 40 rows.
When I initiate a print_r($results). All rows are returned but with json_encode($results), it returns blank screen and only returns if there is a limit of 8.
ini_set("display_errors",1);
$Db = new PDO ( "mysql:host=127.0.0.1;dbname=recycle",'root','' );
$Db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$Query = $Db->prepare('SELECT * FROM recyclable');
$Query->execute();
$Results = $Query->fetchAll(PDO::FETCH_OBJ);
echo json_encode($Results); [error]
//print_r($Results) works.
I have deleted the database and tried it again.Still not working and even tested the same query against other database tables and still not working.
Just can't stress on how much frustration this is causing me. I am using XAMPP
1.8.3 [PHP: 5.5.3]
Upvotes: 1
Views: 389
Reputation: 79
You have to add character set to your pdo connection.
$Db = new PDO ( "mysql:host=127.0.0.1;dbname=recycle;charset=utf8",'root','' );
Upvotes: 1
Reputation: 2146
it can be because of "out of memory" problem.. just do an
ini_set("display_errors",1)"
in the beginning and E_ALL
error
Upvotes: 2