}
+# helper function
function db_send_get($table, $columns, $where, $args) {
$sql = "SELECT $columns FROM $table";
if($where) {
}
+# if no results: returs []
function db_get_rows($table, $columns, $where = '') {
$args = func_get_args();
$args = array_slice($args, 3);
}
# like db_get_rows, but return array of hashes.
+# if no results: returs []
function db_get_assocs($table, $columns, $where = '') {
$args = func_get_args();
$args = array_slice($args, 3);
return $rows;
}
+# if no results: returs []
function db_get_column($table, $columns, $where = '') {
$args = func_get_args();
$args = array_slice($args, 3);
return $column;
}
+# returns first matching row
+# if no results: returns false
function db_get_row($table, $columns, $where = '') {
$args = func_get_args();
$args = array_slice($args, 3);
}
# like db_get_row, but return a hash.
+# if no results: returns false
function db_get_assoc($table, $columns, $where = '') {
$args = func_get_args();
$args = array_slice($args, 3);
return $row;
}
-function db_get_value($table, $columns, $where = '') {
+# if no results: returns false
+function db_get_value($table, $column, $where = '') {
$args = func_get_args();
$args = array_slice($args, 3);
- $result = db_send_get($table, $columns, $where, $args);
+ $result = db_send_get($table, $column, $where, $args);
$value = mysql_fetch_row($result);
if($value !== false) {
return $value;
}
+# returns an integer
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);
+ return (int) call_user_func_array('db_get_value', $args);
}
# call either of these ways: