Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
wfpl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
metaform: new syntax for options, fix radio
[wfpl.git]
/
db.php
diff --git
a/db.php
b/db.php
index
84b23aa
..
14787ac
100644
(file)
--- a/
db.php
+++ b/
db.php
@@
-16,8
+16,8
@@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-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
#
# 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) {
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);
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.
}
# 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);
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;
}
return $rows;
}
+# if no results: returs []
function db_get_column($table, $columns, $where = '') {
$args = func_get_args();
$args = array_slice($args, 3);
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;
}
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);
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.
}
# 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);
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;
}
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);
$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) {
$value = mysql_fetch_row($result);
if($value !== false) {
@@
-257,10
+265,11
@@
function db_get_value($table, $columns, $where = '') {
return $value;
}
return $value;
}
+# returns an integer
function db_count($table, $where = '') {
$args = func_get_args();
array_splice($args, 1, 0, array('count(*)'));
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:
}
# call either of these ways: