Hi I used to write PHP years ago but have been told that my server is to upgrade from PHP4.4 to PHP7. I am out of my depth here and can’t do local host. I have put together a simple DB and PDO connection. Can someone help me with this? I have a simple mySQL database table called PDO. It has 5 records of Name_F, Name_S, DOB. I am trying to iterate the table so that I can display the records on a web page. I was told on another forum to use $stmt. What does stmt even stand for?
Thanks for your help.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
define ('HOSTNAME1', 'mysql09.iomart.com');
define ('USERNAME1', 'otoogc692');
define ('PASSWORD1', 'mauritius');
define ('DATABASE1', 'otoogc692');
function ConnectDB()
{
static $conn = null;
if ($conn === null)
{
$host = HOSTNAME1;
$user = USERNAME1;
$pass = PASSWORD1;
$MyDB = DATABASE1;
$conn = new PDO("mysql:host=$host; dbname=$MyDB; charset=UTF8", $user, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ
]);
}
return $conn;
}
?>
<html>
<body>
<?
echo "Hi There here is the list.";
$conn = connectDB();
$q = $conn->query("SELECT * FROM PDO");
$stmt = $conn->prepare($q);
$stmt->execute();
// What is stmt?
while ($row = $stmt->fetch())
{
echo $stmt['First_N') . "<br/>";
}
?>
</body>
</html>