Hi PHPHelp,
I have a PHP/Mysql application which I have moved from an old server to a new one that has PHP7. I know this mean I must change from mysql to mysqli. Following some tutorials, I have sucessfully updated my mysql code. Most of my application works with the exception of the reading of a tables’ contents. I have created a test script using the connection code (it works), the code that reads the number of tables (that works also) but the code that reads the contents of a table doesn’t work. I have attached the script - conntest.php. Can you see why the table reading code produces a blank screen.
Regards
Gary
ps. apoligies, the layout of the code been lost. Should I have attached instead?
========= CODE ===========
<?php
$dbname = 'csg';
$dbuser = 'root';
$dbpass = 'xxxxxxx';
$dbhost = 'localhost';
// Create connection
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully</br>";
// Check Open dB
mysqli_select_db($dbname, $conn);
// Read number of tables
$test_query = "SHOW TABLES FROM $dbname";
$result = mysqli_query($conn, $test_query);
$tblCnt = 0;
while($tbl = mysqli_fetch_array($result)) {
$tblCnt++;
echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
// Read contents of table 'user'
$sql1 = "SELECT * FROM tbl_user";
$result1 = mysqli_query($conn, $sql1);
$resultcheck = mysqli_num_rows($result1);
while($row = mysqli_fetch_array($result1)) {
$rowCnt++;
echo $row[0]."<br />\n";
}
if (!$rowCnt) {
echo "There are no rows<br />\n";
} else {
echo "There are $rowCnt rows<br />\n";
}
if ($resultcheck > 0) {
while($row = mysqli_fetch_assoc($result1)) {
echo $row['user_name'] . "<br>";
}
}
mysqli_close($conn);
?>
========= CODE ===========