2012-04-16 83 views
1

我正在使用数据库进行多次插入/更新,并且过程非常缓慢。动态地创建未定义的变量调用函数

在试图修复它的过程中,我发现了ibase_prepareibase_execute,现在我正在开发一个函数来完成所有更新并插入它。

问题带有字段中插入/更新的数量,它们是可变的,我不知道如何拨打电话到ibase_execute($query, $field1, $field2,..., $fieldx);

有时是1,其他2,别人多。

<?php 
$dbh = ibase_connect($host, $username, $password); 
$updates = array(1 => 'Eric',5 => 'Filip',7 => 'Larry'); 
$query = ibase_prepare($dbh, "UPDATE FOO SET BAR = ? WHERE BAZ = ?"); 
foreach ($updates as $baz => $bar) { 
    ibase_execute($query, $bar, $baz); 
} 
?> 

任何想法的工作?可以在执行时间定义一个函数吗?在流或类似的东西?

感谢您的时间

回答

1

call_user_func_array应该能够做你想做的。只需将您的字段放入一个数组中:

$result = call_user_func_array("ibase_execute", array("field1"); //Just 1 field 
$result = call_user_func_array("ibase_execute", array("field1", "field2", "field3")); //3 fields 
+0

感谢您的回复, $ fields = new array(1,2,3); $ result = call_user_func_array(“ibase_execute”,$ fields); $ fields = new array(a); $ result = call_user_func_array(“ibase_execute”,$ fields); 这应该工作正常,我会稍后再检查。 此致敬礼, P.S.我不知道如何格式化文本,该死的。 – reverendocabron 2012-04-16 10:35:06