Select::Fields

Specify the table fields to return

Sintaxe

namespace ProtocolLive\PhpLiveDb;

/**

 */
final class Select{
public function Fields(
string|UnitEnum|string[]|UnitEnum[] $Fields
):self;
}
Parameters

$Field - The fields names, subquerys or sql functions;

Examples

Many fields as string
$consult = $Db->Select('users');
$consult->Fields('user_id,name,email,active,lastlogin');
$consult->Run();
//select user_id,name,email,active,lastlogin from users
Many fields as array
$consult = $Db->Select('users');
$consult->Fields(['user_id', 'name', 'email', 'active', 'lastlogin']);
$consult->Run();
//select user_id,name,email,active,lastlogin from users
Subquery as string
$consult = $Db->Select('users u');
$consult->Fields('
user_id,(
select value from socialmedias where name='Telegram' and user_id=u.user_id
) as telegram
');
$consult->Run();
//select user_id,(select value from socialmedias where name='Telegram' and user_id=u.user_id) as telegram from users u
Subquery as array
$consult = $Db->Select('users u');
$consult->Fields([
'user_id',
'(select value from socialmedias where name='Telegram' and user_id=u.user_id) as telegram'
]);
$consult->Run();
//select user_id,(select value from socialmedias where name='Telegram' and user_id=u.user_id) as telegram from users u
Fields as enum
enum UserFields:string{
case Id = 'sys_id';
case Email = 'email';
}

$consult = $Db->Select('users');
$consult->Fields(UserFields::Email);
$consult->Run();
//select email from users