Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Interview question

How does MySQLi handle prepared statements differently from PDO? MySQLi prepared statements PDO से अलग कैसे handle करता है?

Answer

MySQLi uses positional placeholders (?) with a type string for binding, while PDO supports both positional and named placeholders.

$stmt = $mysqli->prepare('SELECT * FROM users WHERE email = ? AND status = ?');
$stmt->bind_param('si', $email, $status);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    echo $row['name'];
}
AspectMySQLiPDO
Placeholder types? only? and :name
Type declarationRequired (s, i, d, b string)Optional, auto-detected

MySQLi positional placeholders (?) और type string का उपयोग करता है, जबकि PDO positional और named दोनों support करता है।

$stmt = $mysqli->prepare('SELECT * FROM users WHERE email = ? AND status = ?');
$stmt->bind_param('si', $email, $status);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    echo $row['name'];
}

Was this answer clear?