DB_common::getListOf() (Previous) (Next) DB_common::getOption()

View this page in Last updated: Sun, 11 May 2008
English | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Plain HTML

DB_common::getOne()

DB_common::getOne() -- Runs a query and returns the first column of the first row

Description

Runs the query provided and returns the data from the first column of the first row then frees the result set.

Parameter

string $query

the SQL query or the statement to prepare

mixed $params

array, string or numeric data to be added to the prepared statement. Quantity of items passed must match quantity of placeholders in the prepared statement: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.

If supplied, prepare()/ execute() is used.

Return value

mixed - the first column's data, NULL if there is no data, or a DB_Error object on failure

Note

This function can not be called statically.

DB_common::getListOf() (Previous) (Next) DB_common::getOption()

Download Documentation Last updated: Sun, 11 May 2008
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
Note by: webmaster@metapundit.net
Be careful using getOne() on columns that may contain null values - you now have no way of knowing whether your query matched any rows or not. Consider the table

users
|id|name|
---+----+
1 | test
2 | NULL
---------
<?php
var_dump
($db->getOne('select name from users where id=1'));
var_dump($db->getOne('select name from users where id=2'));
var_dump($db->getOne('select name from users where foo=1'));
?>


will output "NULL", "NULL", and a db_error object.