Lesson content
Read, practise, then check your understanding
mysqli is MySQL-specific and offers object-oriented and procedural APIs. Enable exception reporting, set charset, and use prepared statements.
Practical example
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$db = new mysqli($host, $user, $password, $name);
$db->set_charset('utf8mb4');
$stmt = $db->prepare('SELECT name FROM users WHERE id = ?');
$stmt->bind_param('i', $id); $stmt->execute();
Transactions group related writes with commit/rollback. Bound values cannot represent SQL identifiers, so allowlist dynamic columns/directions. Use least-privileged database accounts, bounded result sets, timeouts, and centralized connection configuration.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.