简体   繁体   中英

get one result from a query

I tried doing this,

//returns the last updated id
$val = $DB->GetOne("SELECT id FROM table_name ORDER BY id DESC LIMIT 0,1");

But it doesn't work unless I do $DB->GetRow() . So, does this mean that I need to have where clause for the GetOne() to work?

I would imagine that since you are querying for one result, the WHERE clause is essential. If you attempt to get one result without defining what you are looking for, then I don't imagine it will work in the way you intend. Refer to the PHP Code Examples from the ADOdb documentation.

The code in the question will work but there was a bug in the adodb mysql driver where it will return false (instead of NULL) when no results are found. The bug was fixed in 2010 . So you may be experiencing the bug if you're running an old version of adodb.

GetOne returns the content of the first field in the first row of the result set.

Also saying "it's not working" doesn't say much.

Try printing $DB->ErrorMsg() to see what's wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM