JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
document return values of db_get_* when no match
authorJason Woofenden <jason@jasonwoof.com>
Fri, 27 Mar 2015 03:01:37 +0000 (23:01 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Fri, 27 Mar 2015 03:01:37 +0000 (23:01 -0400)
db.php

diff --git a/db.php b/db.php
index efefbda..9540220 100644 (file)
--- a/db.php
+++ b/db.php
@@ -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) {