gpt4 book ai didi

带数组的 PHP bind_param

转载 作者:行者123 更新时间:2023-12-04 21:39:40 35 4
gpt4 key购买 nike

是否可以使用 bind_param()用数组?

例如

$stmt->bind_param('iss', Array(101, 'SomeString 1', 'Some string 2'));
// OR
$stmt->bind_param(Array('iss'), Array(101, 'String1', 'String2'));
// OR
$stmt->bind_param(Array( Array('i', 101), Array('s', 'String1'), Array('s', 'String2') ));

这些示例中的任何一个都可以用 PHP(或任何其他示例)实现吗?

终于可以使用我的函数/类了

$sql->upload( $table, Array('n;id', 's;username=' . $username, 's;password=' . $password) );

功能说明

public function upload( String $table , Array $values )

// Where example array could be Array('s;column=someString', 'i;SomeIntegerColumn=10', 'n;SomeID')
/*
identifier;column=value
Basically where identifier can be "n", "d", "i" or "s"
column is the name of the sql column to inset the value to
value is the string/integer/double to instert in the the column

Example query with the array mentioned above would be
"INSERT INTO $table(column, SomeIntegerColumn, SomeID) VALUES(?, ?, NULL)"
*/

我的项目很快就会在 GitHub 上发布 :) 非常感谢!

最佳答案

如果您的 PHP 没有过时(即 >= 5.6),只需在第一个示例中添加三个点,

$stmt->bind_param('iss', ...array(101, 'SomeString 1', 'Some string 2'));

关于带数组的 PHP bind_param,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40717625/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com