On a new installation raspberry pie LAMP mysqli_query() returns null result.
There is no error message and nothing shows up in the /var/log/apache2/error.log.
If I submit the same query with the command line mysql, it works correctly.
I created a simple script to demonstrate how to connect webpages to mysql with php. This is a pretty simple script but it doesn’t work. I feel like I have done this a thousand times. This is the first time it didn’t work.
Using phpinfo() I found that mysqli.allow_local_infile was set to “Off”. I changed it to “On” because I found that in other systems that I have, it was On.
This machine is running Debian version 12 (bookworm)
PHP version is 8.2 with Apache/2.4.59 (Debian)
mariadb Ver 15.1 Distrib 10.11.6-MariaDB
The simple program:
<?php
$hd=mysqli_connect('localhost', 'root', 'rb24', 'testdb') or die ("didn't connect");
$q="SELECT firstName, lastName, acctNumber FROM addressBook";
$res=mysqli_query($hd, $q);
while ($row=mysqli_fetch_array($res));
{
$firstName=$row['firstName'];
$lastName=$row['lastName'];
$acctNumber=$row['acctNumber'];
echo("firstName is $firstName <hr>
lastName is $lastName <hr>
acctNumber is $acctNumber <hr>");
var_dump($row);
}
?>
from the mysql command line:
MariaDB [testdb]> SELECT firstName, lastName, acctNumber FROM addressBook;
+———–+———-+————+
| firstName | lastName | acctNumber |
+———–+———-+————+
| Adam | Allan | 55 |
| Billy | Baker | 64 |
+———–+———-+————+
2 rows in set (0.001 sec)
Does anybody have some idea what is going on?
The query works in phpmyadmin and mysql command line.
I have done apt-get update/upgrade.
I examined the output of phpinfo() for differences in this installation compared to one that was working correctly.
I examined the php.ini file to try to find something off. Other than the mysqli.allow_local_infile set to “Off” and changing it to “On” I am out of ideas.