-1

I have this MySql query that is not returning the output but If I define a limit below 200 records the return works ( return the records ).

normally this query must return 5000 records .

So the question is what I doing wrong and what I have to Do to return all rows .

Is there any configuration in php.ini or other file that fix this query?

    getConnection();
    $connection =  getConnection();
    $stmt = $connection->prepare("SELECT * FROM estadoactual limit 200");
    $stmt->execute( );

    $rows = $stmt->fetchAll();
    echo json_encode($rows);

If I put limit 200 the query works but if I remove this limit then don't

I try exand de the memory limit in php.ini to 512MB/2048MB but not work

exequielc
  • 681
  • 1
  • 11
  • 32
  • 4
    In what way doesn't it work above 200 records? btw the mysql_* extension was removed from PHP version 7 you should now be using PDO – SpacePhoenix Mar 01 '17 at 22:07
  • 2
    You'll need to tell us what goes wrong. Just saying "it doesn't work" doesn't give people much to go on! – Ben Hillier Mar 01 '17 at 22:09
  • Maybe you are hitting the memory limit or execution time limit in PHP? Too many things, you need to debug more. Is error logging enabled and being checked? – chris85 Mar 01 '17 at 22:11
  • Run query without limitation & share logs please. – behkod Mar 01 '17 at 22:14
  • 3
    Do not use `mysql_query` as it is [deprecated](http://php.net/manual/en/function.mysql-query.php) from PHP 5.5 – MaxZoom Mar 01 '17 at 22:20
  • 2
    This is probably a character encoding problem. Use `mysql_query("SET CHARACTER SET utf8")` before doing the query. Having said that: please convert your code to `mysqli` or `PDO`, as these `mysql_` functions are not supported anymore in the latest versions of PHP. – trincot Mar 01 '17 at 22:24
  • my server hostmonster uses Php 5.5 , I never work with PDO how I change that query to work with PDO ? – exequielc Mar 01 '17 at 22:27
  • 1
    Here is the [PDO](http://php.net/manual/en/ref.pdo-mysql.php) manual – MaxZoom Mar 01 '17 at 22:29
  • I change the code but with pdo not return all rows @MaxZoom – exequielc Mar 01 '17 at 23:23
  • @trincot this is the right answer to my problem. please post it so I can mark this one correct – exequielc Mar 03 '17 at 11:15

1 Answers1

1

json_encode will fail with the value false when the string passed to it has invalid UTF8 sequences. This practically means one of your records has a string with non-ASCII characters, and a different character encoding is used. There are other possible reasons as well, but often this is the problem.

When json_encode returns false, you should check which error occurred with json_last_error_msg.

When reading data from the database, make sure to use utf-8 encoding. In your case you should use call this function:

mysql_query("SET CHARACTER SET utf8") 

...before doing the query.

Having said that: please convert your code to mysqli or PDO, as these mysql_ functions were deprecated a few years ago, and are not supported anymore in the latest versions of PHP.

Community
  • 1
  • 1
trincot
  • 317,000
  • 35
  • 244
  • 286