X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=db.php;h=0a1369fc967fca4fd32c72e83f150c8d55d84f79;hb=b0b28a4587992b92f47abb0429df0e1eaf7f151f;hp=065ac0ea11f69b1b2ccf264843fbcf72cc1c6dcd;hpb=d03e8554ee3e80a6333126e67dd4c20f54ec700e;p=wfpl.git diff --git a/db.php b/db.php index 065ac0e..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,9 +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_shift($args)); } elseif($chr == 'i') { - $int = format_int(array_pop($args)); + $int = format_int(array_shift($args)); if($int == '') $int = '0'; $out .= $int; } else { @@ -210,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');