In the "mysql" database there is a field with the type "json" (MySQL 5.7). "PHP" categorically refuses to display this field itself, while if it is banal to remove this field from the sample, everything is fine. I also tried to execute the query in "phpmyadmin" - everything is fine. What could be the problem?

Connection "PHP":

mysql_select_db("datas" ,$db); $sql = mysql_query('SELECT * FROM test',$db); echo '<pre>'; while ($row = mysql_fetch_assoc($sql)) { print_r ($row); } echo '</pre>'; mysql_close($db); 

PHP connection using mysqli:

 $result = $mysqli->query('SELECT * FROM test'); echo '<pre>'; foreach ($result->fetch_all(MYSQLI_ASSOC) as $row){ print_r ($row); } echo '</pre>'; 

In both cases, everything works if you remove the json field from the selection.

Separately on request:

  • does not work:

     SELECT * FROM test 
  • does not work:

     SELECT jsondata FROM test 
  • does not work:

     SELECT id,name,jsondata FROM test 
  • works:

     SELECT id,name FROM test 

Php version: 5.3.29

Version of mysql: 5.7.13

    1 answer 1

    The situation was able to reproduce. If there is an opportunity to use an alternative PDO extension, I would suggest using it - it processes JSON data correctly.

     try { $pdo = new PDO( 'mysql:host=localhost;dbname=test', 'root', '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $query = "SELECT * FROM test"; $cat = $pdo->query($query); $results = $cat->fetchAll(); echo '<pre>'; print_r($results); echo '</pre>'; } catch (PDOException $e) { echo "Ошибка выполнения запроса: " . $e->getMessage(); } 
    • I tried your example, as a result the error appears: Fatal error: Call to a member function fetchAll () on a non-object If you insert the json field - sergey72