X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=db.php;h=14787ac830199ee5a9e2bde4bb5acc561e45f25f;hb=f6fdd9deec6c7815f5877270e746e1bd1201a726;hp=84b23aa685ca019a4f3085df57f09d92836feb55;hpb=35b2973c5ed7fbba047cf67a5e84957bfdedc7c7;p=wfpl.git diff --git a/db.php b/db.php index 84b23aa..14787ac 100644 --- a/db.php +++ b/db.php @@ -16,8 +16,8 @@ # along with this program. If not, see . -require_once(__DIR__ . '/encode.php'); -require_once(__DIR__ . '/format.php'); +require_once(__DIR__.'/'.'encode.php'); +require_once(__DIR__.'/'.'format.php'); # db_connect() -- connect to a mysql database # @@ -161,6 +161,7 @@ function _db_printf($str, $args) { } +# helper function function db_send_get($table, $columns, $where, $args) { $sql = "SELECT $columns FROM $table"; if($where) { @@ -171,6 +172,7 @@ function db_send_get($table, $columns, $where, $args) { } +# if no results: returs [] function db_get_rows($table, $columns, $where = '') { $args = func_get_args(); $args = array_slice($args, 3); @@ -187,6 +189,7 @@ function db_get_rows($table, $columns, $where = '') { } # 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); @@ -202,6 +205,7 @@ function db_get_assocs($table, $columns, $where = '') { return $rows; } +# if no results: returs [] function db_get_column($table, $columns, $where = '') { $args = func_get_args(); $args = array_slice($args, 3); @@ -217,6 +221,8 @@ function db_get_column($table, $columns, $where = '') { 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); @@ -230,6 +236,7 @@ function db_get_row($table, $columns, $where = '') { } # 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); @@ -242,10 +249,11 @@ function db_get_assoc($table, $columns, $where = '') { 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) { @@ -257,10 +265,11 @@ function db_get_value($table, $columns, $where = '') { 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: