Home  >  Article  >  Backend Development  >  php 踩坑 PDO foreach bindParam

php 踩坑 PDO foreach bindParam

藏色散人
藏色散人forward
2019-12-31 17:16:362337browse

Official document https://www.php.net/manual/zh/pdostatement.bindparam.php

Note:

bindParam The second parameter is mixed &$variable is reference by value

Correct usage ($val by reference):

<?php
foreach ($params as $key => &$val) {
    $sth->bindParam($key, $val);
}
?>

Wrong usage ($val by value, because bindParam needs &$ variable):

<?php
foreach ($params as $key => $val) {
    $sth->bindParam($key, $val);
}

For more PHP related knowledge, please visit PHP tutorial!

The above is the detailed content of php 踩坑 PDO foreach bindParam. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lukachen.com. If there is any infringement, please contact admin@php.cn delete