我在php.net上找到了以下代码。我正试图为mysqli库编写一个包装器,使事情变得非常简单。如果这会降低性能,我将跳过它并找到另一种方法,如果这个方法有效,那么我将这样做。
我有一个单独的查询函数,如果有人传入多个变量,我假设必须准备好函数。在数组中传递给
mysqli_stmt_bind_param
是
call_user_func_array
我有种感觉会让事情变慢。我说的对吗?
<?php
/* just explaining how to call mysqli_stmt_bind_param with a parameter array */
$sql_link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
$type = "isssi";
$param = array("5", "File Description", "File Title", "Original Name", time());
$sql = "INSERT INTO file_detail (file_id, file_description, file_title, file_original_name, file_upload_date) VALUES (?, ?, ?, ?, ?)";
$sql_stmt = mysqli_prepare ($sql_link, $sql);
call_user_func_array('mysqli_stmt_bind_param', array_merge (array($sql_stmt, $type), $param);
mysqli_stmt_execute($sql_stmt);
?>