mysqli prepared statement without bind_param

前端 未结 3 1490
予麋鹿
予麋鹿 2021-01-27 03:09

I have this code for selecting fname from the latest record on the user table.

$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$sdt=$mysqli-&g         


        
3条回答
  •  盖世英雄少女心
    2021-01-27 03:50

    Actually, if i correct your script, it'll be like this:

    $mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
    $sdt = $mysqli->prepare('SELECT fname FROM user ORDER BY id DESC LIMIT 1');
    $sdt->execute();
    $sdt->bind_result($code);
    $sdt->fetch();
    echo $code;
    

    So, without bind_param, usually this works for me:

    $bla = $_POST['something'];
    $mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
    $stmt = $mysqli->prepare("SELECT fname FROM user WHERE bla = " . $bla . " ORDER BY id DESC LIMIT 1");
    $stmt->execute();
    $stmt->bind_result($code);
    $stmt->fetch();
    echo $code;
    

    That might help.

提交回复
热议问题