JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
session_new() returns id, fixed db_count()
[wfpl.git] / db.php
diff --git a/db.php b/db.php
index 065ac0e..0a1369f 100644 (file)
--- 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');