tags:

views:

88

answers:

1

I have two functions like this:

function mysql_safe_query($format) {
 $args = array_slice(func_get_args(),1);
 $args = array_map('mysql_safe_string',$args);
 $query = vsprintf($format,$args);
 $result = mysql_query($query);
 if($result === false) echo '<div class="mysql-error">',mysql_error(),'<br/>',$query,'</div>';
 return $result;
}

function mysql_row_exists() {
 $result = mysql_safe_query(func_get_args());
 return mysql_num_rows($result) > 0;
}

The problem is that the second function won't work because it passes the args to the first one as an array, when it expects them as different parameters. Is there any way to get around this, preferably without modifying mysql_safe_query?

+4  A: 

How about using call_user_func_array('mysql_safe_query', func_get_args());?

John Fiala
http://uk.php.net/func_get_args says: "Note: Because this function depends on the current scope to determine parameter details, it cannot be used as a function parameter. If this value must be passed, the results should be assigned to a variable, and that variable should be passed."
VolkerK
perfect!@volker: doesn't seem to be an issue in this case.
Mark
@volker: err..nevermind. you're right. it didn't complain last time, but now it is. I guess it's better to obey the warnings.
Mark