I have two databases. Both are MySQL 8.x. Both have the exact same database schema, database name, database user, database password, and charset. The only difference is they are on different servers.
If I run my PHP code using the database on server 1, it works fine.
If I run my PHP code using the database on server 2, every mysqli_query
returns false.
I can see my database connection to server 2 is fine (if I run mysqli_stat on the mysqli object it outputs what I would expect). If I connect to server 2 via the command line and manually run the SQL queries which are failing, they return normal results as expected.
Everything I am doing is standard:
Connection:
$db = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password, $mysql_database, $mysql_port) or die("Could not connect database");
mysqli_set_charset($db, $mysql_charset);
if (mysqli_connect_errno()) {
throw new Exception("Failed to connect to MySQL: " . mysqli_connect_error());
}
Example query:
global $db;
$query = "SELECT * FROM users";
$result = mysqli_query($db,$query);
$array = array();
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$array[] = $row;
}
}
I cannot figure this out.
Can any of you think of any reason mysqli_query
would fail on a database it can connect to and using a query which is valid?
Server 1 is on my local machine, server 2 is a managed digital ocean database.