0

At first I'm sorry for posting duplicate question I always try to find answers and never to ask. But nothing solved my problem. I have a MySql DB with table named data. I cannot change the table name. When I execute SELECT * FROM `data` or SELECT * FROM data in phpMyAdmin, the query works correctly but when I execute it in PHP script the query() returns false

<?php

$conn = new mysqli('localhost', 'username', 'pswd', 'dbname');
if ($conn->connect_error) {
    die('connection error');
}
$result = $conn->query("SELECT * FROM `data`");

var_dump($result);

echo "-".$conn->error."-";

I have looked at these questions:

Mysql query works in phpmyadmin but not in php (due to date)

Mysql query works in Phpmyadmin but not works in PHP

MySQL query working in phpmyadmin but not in php

and some others...

2 Answers2

0
$result ="SELECT * FROM `data`";
$row=mysqli_query($conn,$result);
while($row_result=$row->fetch_assoc())
print_r($row_result);
Mazhar Hussain
  • 125
  • 1
  • 11
  • the `$row` variable is set to false as result of mysqli_query – Martin Bodický Jan 10 '18 at 09:59
  • you can fetch data with while loop i check it is ok – Mazhar Hussain Jan 10 '18 at 10:02
  • no i can't, when i var_dump($row) i get returned bool(false) – Martin Bodický Jan 10 '18 at 10:05
  • Thank you for this code snippet, which might provide some limited short-term help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its long-term value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you've made. – Toby Speight Jan 10 '18 at 12:23
0

With your replies I've got some idea what to try next.I've created copy of the table on my own server and tried changing data types. One of data types in original table is set as JSON, when i changed it to TEXT it started to work.