X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=db.php;h=0a1369fc967fca4fd32c72e83f150c8d55d84f79;hb=9a2257958f77e293a6f49d741405521f02855896;hp=3e4f725c30758f0027a70afbf6dd6c15c06adff8;hpb=848c8a4d215f9cce1db0a7d37e733b5959b8210f;p=wfpl.git diff --git a/db.php b/db.php index 3e4f725..0a1369f 100644 --- a/db.php +++ b/db.php @@ -111,7 +111,6 @@ function db_printf($str) { # This function does the work, but takes the parameters in an array function _db_printf($str, $args) { - $args = array_reverse($args); # because array_pop() takes from the end $out = ''; while($str) { $pos = strpos($str, '%'); @@ -129,11 +128,11 @@ function _db_printf($str, $args) { $str = substr($str, $pos + 2); if($chr == '"') { - $out .= '"' . enc_sql(array_pop($args)) . '"'; + $out .= '"' . enc_sql(array_shift($args)) . '"'; } elseif($chr == 's') { - $out .= enc_sql(array_pop($args)); + $out .= enc_sql(array_shift($args)); } elseif($chr == 'i') { - $int = format_int(array_pop($args)); + $int = format_int(array_shift($args)); if($int == '') $int = '0'; $out .= $int; } else { @@ -212,6 +211,12 @@ function db_get_value($table, $columns, $where = '') { return $value; } +function db_count($table, $where = '') { + $args = func_get_args(); + array_splice($args, 1, 0, array('count(*)')); + return call_user_func_array('db_get_value', $args); +} + # call either of these ways: # # db_insert('people', 'name,company', 'jason', 'widgets ltd');