如何用数组中的元素替换char的所有出现? [英] How to replace all occurencies of char with elements from array?

查看:103
本文介绍了如何用数组中的元素替换char的所有出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下字符串:

$sql = sql_prepare("UPDATE `test` SET `item1` = ?, `item2` = ?, `item3` = ?", array(50, 55, 60));

我需要创建"sql_prepare"函数,以匹配所有出现的?" char并替换为数组中的元素,因此最终的sql将是:

I need to create "sql_prepare" function that will match all occurencies of '?' char and replace with elements from array, so final sql will be:

UPDATE `test` SET `item1` = 50, `item2` = 55, `item3` = 60

我该怎么做?

推荐答案

当mysqli和PDO都实现真实的预处理语句时,为什么要尝试使用旧版mysql_ * API伪造预处理语句?

Why try to fake a prepared statement with the legacy mysql_* API, when both mysqli and PDO implement real prepared statements?

PDO示例:

if ($prepped = $pdo -> prepare ('UPDATE `test` SET `item1` = ?, `item2` = ?, `item3` = ?'))
{
    $res = $prepped -> execute (array (50, 55 ,60));
}

这篇关于如何用数组中的元素替换char的所有出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆