ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:getone

This is an old revision of the document!


GetOne

Syntax
  mixed getOne(
     string $sql
     )

Executes the SQL and returns the first column of the first row. The recordset and remaining rows are discarded for you automatically. If an error occurs, either false or null is returned depending on the value of $ADODB_GETONE_EOF.

You can use errorMsg() to get any the error details.

Controlling the response if no records are found

By default, getOne returns NULL if no records are found. The global variable $ADODB_GETONE_EOF can be set to any value to indicate no match

Usage

$ADODB_GETONE_EOF = "-1";
 
$SQL = "SELECT MAX(tickets) FROM arena WHERE zip_code = '80111'";
$maxTickets = $db->GetOne($SQL);
 
if ($maxTickets == -1)
    print "There are no arenas in zip code 80111";
elseif ($maxTickets == 0)
    print "No tickets have been sold in zip code 80111";
else
    print "The maximum number of tickets sold by arenas 
           in Zip Code 80111 is $maxTickets";
v5/reference/connection/getone.1452984630.txt.gz · Last modified: 2017/04/21 11:34 (external edit)