首先,我想说我是PDO的新手。我曾尝试过一次但是因为我发现oop解决方案很复杂甚至不可能(SELECT * FROM table_name
)我决定使用PDO。
但我不确定我是否做得对,所以我想对我所做的事情提出批评。我正在翻译" mysqli stmt到pdo。以下是我已经翻译过的一个例子:#/ p>
// 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);
我做得对吗?