Originally Posted on Stack Overflow
First of all I want to say that I’m new to PDO. I did tried it once but since I found the oop solution complicated and even impossible (SELECT * FROM table_name
) I decided to use PDO.
But I’m not sure if I do it right, so I’d like to take criticism about what I’ve done. I’m “translating” the mysqli stmt to pdo. Here’s an example from one thing I’ve “translated”:
// Client IP has been defined previously, // But for the example: $ ip = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'; $ sql_ip = inet_pton($ ip); // IPV6 try { $ stmt = $ pdo->prepare('SELECT * FROM sessions WHERE s_ipv4 = :s_ipv4 OR s_ipv6 = :s_ipv6'); $ stmt->bindParam(':s_ipv4', $ sql_ip); $ stmt->bindParam(':s_ipv6', $ sql_ip); $ stmt->execute(); if ($ stmt->rowCount() === 0) { // No rows } else { // Do something } } catch (Exception $ exception) { die ($ exception->getMessage()); } unset($ stmt);
Am I doing it right?