且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP用数组中的字符串替换字符

更新时间:2023-02-21 15:47:36

不幸的是,mysqli没有一个很好的方法来获取查询.您可以使用一种方法来替换参数:

Unfortunately, mysqli does not have a good way to get just the query. You could use a method to do the replacement of your parameters:

function populateSql ( string $sql, array $params ) : string {
    foreach($params as $value)
        $sql = preg_replace ( '[\?]' , "'" . $value . "'" , $sql, 1 );
    return $sql;
}