开发者

Equivalent mysqli

I have this:

$rs = mysql_query('select zip  from _zipcode where zip like "'.$consulta .'%"');

How开发者_JS百科 I can convert the code above to mysqli?

I tried something like this, but is not completed

($sql = $db -> prepare('select zip from _zipcode where zip // ));


if($sql = $db->prepare('select zip from _zipcode where zip like ?'))
{
    $sql->bind_param("s", $consulta);
    $sql->execute();
    $sql->bind_result($zip);

    while ($sql->fetch()) {
        echo "Zip: $zip\n";
    }

    $sql->close();
}

All based off of http://www.php.net/manual/en/mysqli.prepare.php


Your Line:

     $rs = mysql_query('select zip  from _zipcode where zip like "'.$consulta .'%"');

SQLi Line:

        $query="select zip  from _zipcode where zip like " .$consulta . "%";
        $rs = mysqli_query($connection_information,$query) or  die(mysqli_error($connection_information));
       $row_rs = mysqli_fetch_assoc($rs);
       $totalRows_rs = mysqli_num_rows($rs);

    do {  
        echo $row_rs['zip'];

        } while ($row_rs = mysqli_fetch_assoc($rs));
          $rows = mysqli_num_rows($rs);
          if($rows > 0) {
           mysqli_data_seek($rs, 0);
           $row_rs = mysqli_fetch_assoc($rs);
                          }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜