I need to convert my website to MySQLi with OOP:
Below works. Is there anything I've missed or need to do better or differently?
I really need to get this done so any help would be appreciated.
<?php
// OOP way at very top of page
$db = new mysqli('localhost','username','password','database');
if ($db->connect_error) {
trigger_error('Database connection failed: ' . $db->connect_error, E_USER_ERROR);
exit();
}
?>
BUNCH OF website stuff/then my SELECT:
<?php
// Set up query
$query = "SELECT pagename, image, name FROM table";
// OOP way
$result = $db->query($query);
while ($row = $result->fetch_assoc())
{
?>
<figure>
<a href="<?php echo ($row["pagename"]); ?>">
<img src="<?php echo ($row["image"]); ?>"></a>
<figcaption>
<a href="<?php echo ($row["pagename"]); ?>">
<h2><?php echo ($row["name"]); ?></h2></a>
</figcaption></figure>
<?php
}
// OOP way
$result->free();
$db->close();
?>