3

如果这是我的代码:

    $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到两个?s?

或者有没有更好的方法来做到这一点?

4

1 回答 1

4

你可以这样做

$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)
于 2012-12-11T08:17:36.900 回答