Repository navigation
Select statements
me-awesome edited this page Nov 1, 2020
·
1 revision
$table = new TheLeague\Database\Database::table( 'users' )
// select * from wp_users
$table->get();
// select distinct * from wp_users
$table->distinct()->get();
// select SQL_CALC_FOUND_ROWS * from wp_users
$table->found_rows()->get();// select id from wp_users
$table->select( 'id' )->get();
// select id, user_login from wp_users
$table->select( 'id, user_login' )->get();
// select id, user_login from wp_users
$table->select( array( 'id', 'user_login' ) )->get();
// select id, user_login as username from wp_users
$table->select( array( 'id', 'user_login as username' ) )->get();
// select id, user_login as username from wp_users
$table->select( array(
'id',
'user_login' => 'username'
) )->get();// select count(*) from wp_users
$table->selectCount()->get();
// select count( id ) as count from wp_users
$table->selectCount( 'id', 'count' )->get();
// select sum( id ) as total from wp_users
$table->selectSum( 'id', 'total' )->get();
// select avg( id ) as average from wp_users
$table->selectAvg( 'id', 'average' )->get();// select * from wp_users WHERE user_email = 'admin@example.com' LIMIT 0, 1;
$table->where( 'user_email', 'admin@example.com' )->one();$email = $table->select( 'user_email' )->where( 'ID', 123 )->getVar();