0

I installed PHP, MySQL 5, and Light TPD on my Beaglebone Black Wireless (running Debian image 2017-07-01). I tried creating a webpage that displays a MySQL table, but noticed that the table wasn't even appearing. So in order to isolate the problem, I created a simple PHP program that does nothing but display some text and a table with only one row. I began adding things from the larger program one at a time until I found what was causing the tables to disappear. Here is the relevant code:

<html>
<head>
<title>Table Test</title>

<link rel="stylesheet" type="text/css" href="styles.css">

</head>

<BODY>

<?php include('NAV.php') ?>

<?php

echo "Table Test<br>";

//////////////////////////////////////////////////////
//        Connecting to the Database
//////////////////////////////////////////////////////
$con = mysqli_connect("localhost","root","pass", "dB");

//Print HTML table
echo "<TABLE width=40% cellpadding=5 cellspacing=0 border=1>";
echo "
<TR>
<TD><b>ID</TD>
<TD><b>LOCATION</TD>
<TD><b>SEQUENCE</TD> 
<TD><b>TIME</TD>
<TD><b>UPDATE</TD>
<TD><b>DELETE</TD> 
</TR>";

?>

</body>
</html>

I discovered that this line is what causes the problem:

$con = mysqli_connect("localhost","root","pass", "dB");

The table displays just fine on an older Beaglebone (Debian image 2015-11-12). I find it hard to believe that simply declaring a variable would cause an entire table to dissappear. Any help in this matter would be greatly appreciated.

UPDATE (8/15/2017 13:04 EST): I checked the error log (/var/log/lighttpd/error.log) and found the following:

2017-08-15 17:02:39: (mod_fastcgi.c.2702) FastCGI-stderr: PHP Fatal 
error:  Call to undefined function mysqli_connect() in /var/www
/html/TABLE2.php on line 25
Tomasm64
  • 13
  • 4
  • `View Source ... ` is your friend. – O. Jones Aug 15 '17 at 16:56
  • Note: The object-oriented interface to `mysqli` is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete `mysql_query` interface. Before you get too invested in the procedural style it’s worth switching over. Example: `$db = new mysqli(…)` and `$db->prepare("…”)` The procedural interface exists is an artifact from the PHP 4 era when `mysqli` API was introduced and should not be used in new code. – tadman Aug 15 '17 at 17:02
  • @tadman Thanks for letting me know. I'll try using it as an object and get back to you guys – Tomasm64 Aug 15 '17 at 17:12
  • It might not fix anything, but it'll make your code easier to read which is always a win. Don't forget to turn on [error reporting via exceptions](https://stackoverflow.com/questions/14578243/turning-query-errors-to-exceptions-in-mysqli) so you don't miss any errors. For a general PHP survival guide, see [PHP the Right Way](http://phptherightway.com). – tadman Aug 15 '17 at 17:13
  • Based on that error, it appears the mysqli extension is not enabled. Check your PHP configuration for that. – Don't Panic Aug 15 '17 at 17:16
  • Possible duplicate of [Fatal error: Call to undefined function mysqli\_connect()](https://stackoverflow.com/questions/25281467/fatal-error-call-to-undefined-function-mysqli-connect) – Don't Panic Aug 15 '17 at 17:26
  • What would I look for exactly to see if the extension is enabled? – Tomasm64 Aug 15 '17 at 17:45
  • You can check `phpinfo()` to verify that it isn't installed/enabled. I haven't installed it on debian before, but [here's a Q&A about that that should be helpful](https://stackoverflow.com/questions/23254914/mysqli-extension-is-missing-debian). – Don't Panic Aug 15 '17 at 17:59
  • [The PHP documentation also includes installation information.](http://php.net/manual/en/mysqli.installation.php) – Don't Panic Aug 15 '17 at 18:01
  • Thanks everyone for your help! I did some searching and I figured it out. All I had to do was add the following line in php.ini – Tomasm64 Aug 15 '17 at 18:34
  • `extension=mysqli.so` – Tomasm64 Aug 15 '17 at 18:35

0 Answers0