Dynamically bind mysqli_stmt parameters and then bind result (PHP)

后端 未结 4 1834
忘了有多久
忘了有多久 2020-12-03 12:27

I\'m trying to dynamically bind mysql_stmt parameters and get the result in an associative array. I\'ve found this post here on stackoverflow where Amber posted an answer wi

4条回答
  •  执笔经年
    2020-12-03 13:31

    Just to compare excellent answers from @Emmanuel and @matzino with the code you can get if choose PDO over mysqli:

    $sql = "SELECT `first_name`,`last_name` FROM `users` WHERE `country` =? AND `state`=?";
    $params = array('Australia','Victoria');
    
    $stm = $query->prepare($sql);
    $stm->execute($params); 
    $results = $stm->fetchAll(); // or fetch() or fetchColumn() depends on expected type
    

    whoops, that's all?

提交回复
热议问题