# 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, '%');
$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 {
return $value;
}
+function db_count($table, $where = '') {
+ return db_get_value($table, 'count(*)', $where);
+}
+
# call either of these ways:
#
# db_insert('people', 'name,company', 'jason', 'widgets ltd');