November 24th, 2003
GetOne and GetCol
ADODB has a few other features that are quite convenient — GetOne() and GetCol()
GetOne() extracts a single value from a database query into a PHP variable. For example:
$userid = $db->GetOne("SELECT userid FROM users WHERE users.username='$username'");
The code above would place the userid in the PHP variable $userid, based on the lookup by username.
GetCol() returns an array of values found for a single column in a database table, as follows:
$active_users = $db->GetCol("SELECT userid FROM users WHERE active='$active'");
The above code places an array of userids in the PHP variable $active_users.
These are just a couple of ways that ADODB can make your life a lot easier when it comes to database queries.
On top of ease-of-use, ADODB allows portability, since it supports many databases. Even if you are not planning to use another database anytime soon, ADODB still makes programming database queries a lot more simple!
Filed under: PHP/MySQL
Comments Off