MySQL / PHP:如何在准备好的语句中将参数绑定到两个(?)?
作者:互联网
如果这是我的代码:
$mysqli = new mysqli("localhost", "user", "password", "mydb");
$city = "Some";
$q = "SELECT District FROM City WHERE (Name=? OR ? IS NULL)";
if ($stmt = $mysqli->prepare($q)) {
// How to Bind $city here?
}
如何将$city绑定到两个?
还是有更好的方法来做到这一点?
解决方法:
你可以这样做
$stmt -> bind_param("for first ?", 'for second ?');
或尝试像
/* Bind our params */
$stmt->bind_param('ss', $Name, $city);
/* Set our params */
$Name= "hello";
$city= "city";
/* Execute the prepared Statement */
$stmt->execute();
值可以是:
i - Integer
d - Decimal
s - String
b - Blob (sent in packets)
标签:mysqli,prepared-statement,php 来源: https://codeday.me/bug/20191031/1976434.html