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...

11
  • Have you checked mysqli_error? Commented Jan 10, 2018 at 9:32
  • returns emty string "" Commented Jan 10, 2018 at 9:34
  • That seems unlikely. Where and how are you using it? Commented Jan 10, 2018 at 9:35
  • check error by $conn->query("SELECT * FROM data") or die ($conn->error); Commented Jan 10, 2018 at 9:36
  • share full code... Commented Jan 10, 2018 at 9:37

2 Answers 2

0
$result ="SELECT * FROM `data`";
$row=mysqli_query($conn,$result);
while($row_result=$row->fetch_assoc())
print_r($row_result);
Sign up to request clarification or add additional context in comments.

4 Comments

the $row variable is set to false as result of mysqli_query
you can fetch data with while loop i check it is ok
no i can't, when i var_dump($row) i get returned bool(false)
Thank you for this code snippet, which might provide some limited short-term help. A proper explanation would greatly improve 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.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.