0

I have a virtual server and Xamp software is installed on it I have built in a MySQL service that can be easily controlled using database management software, but when I put the same user in PHP code and another server to remotely use the output And we will encounter the following errors

The above code is executed correctly at localhosts but does not run remotely

Problem not running query in MySQL database remotely

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$servername = "MyServer";
$username = "User";
$password = "MyPassword";
$dbname = "DBName";
$mysqli = new mysqli($servername, $username, $password,$dbname);
$result = $mysqli->query("SELECT * FROM users");
$row = $result->fetch_array();
echo $row['name'];

Eror :

Warning: mysqli::query(): Couldn't fetch mysqli in /home2/irpixeli/domains/irpixel.ir/public_html/dbsync.php on line 15 Fatal error: Uncaught Error: Call to a member function fetch_array() on bool in /home2/irpixeli/domains/irpixel.ir/public_html/dbsync.php:16 Stack trace: #0 {main} thrown in /home2/irpixeli/domains/irpixel.ir/public_html/dbsync.php on line 16

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Error ```Uncaught Error: Call to a member function fetch_array() on bool``` means that there is an error in your query. It might be that there is no such table named ```users```. Call ```mysqli_error($mysqli)``` to show the error message – Kristian Jan 11 '20 at 17:48
  • 1
    Are the credentials the same on the remote server? Sounds like the connection is not successful, causing the query to fail, OR the query is failing for some other reason making the result return false instead of a recordset. May need to added error checking at the connection and the query. – Paul T. Jan 11 '20 at 17:50
  • [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) – Dharman Jan 11 '20 at 17:53
  • But the same code is executed correctly in localhosts, but not remotely – Mahdi Azimi Jan 11 '20 at 17:53

0 Answers0