$sql = "SELECT * FROM users"; $result = mysqli_query($conn, $sql); if (!$result) { echo "Error: " . mysqli_error($conn); }
$stmt = $pdo->prepare("INSERT INTO users (name, email) VALUES (?, ?)"); if (!$stmt) { $error = $pdo->errorInfo(); echo "Error: " . $error[2]; }In this example, the errorMessage is obtained using the errorInfo function after preparing an INSERT query using PDO. If the query fails, the error message will be displayed. Package/Library: PHP Database Extensions - mysqli and PDO.