我在MySQL ip_address
中有一个列VARBINARY(16)
,我正试图在PHP
中对where子句进行条件化处理:
$ip_address = inet_pton($ip_address);
$SQL = "SELECT location,
added
FROM ips
WHERE ip_address = BINARY '" . $ip_address . "'";
...
但是,这会返回0
行。我做错了什么?
答案 0 :(得分:0)
尝试使用prepared statement:
$stmt = $conn->stmt_init();
$SQL = "SELECT location, added FROM ips WHERE ip_address = BINARY ?";
$stmt->prepare($sql);
$stmt->bind_param('s', $ip_address);
$stmt->bind_result($location, $added);
$stmt->execute();
$stmt->fetch();