1. Go to this page and download the library: Download grithin/phpdb library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
grithin / phpdb example snippets
$db->column('select name from user');
$db->column_key('id', 'select name from user');
$db->value('select name from user where id = 2');
$table = 'users';
$query = [
'id ? >' => 10, # '?' indicates the operator will appear next
'name ? is not' => null # null values are presented to the database as string NULL
'disabled' => null,
'gender' => 'm'
':last_login' => 'DATE()' # the ":" preface indicates not to escape the value part
];
$db->rows($table, $query)
$db1 = Db::init(null, $config1);
Db::row('user',$id); # on $db1 instance
$db1->row('user',$id);
$db2 = Db::init('secondary', $config2);
Db::row('user',$id); # still on $db1 instance
$db2->row('user',$id);
Db::primary_set('secondary');
Db::row('user',$id); # on $db2 instance
$db = Db::primary();
$db = Db::$instances['main'];
'select * from user where id = '.Db::quote($id);
'select '.Db::identity_quote('table.max').' from '.Db::identity_quote('table').' where id = 1'
Db::value('select name from user where id = 1');
#> 'bob'
Db::row('select * from user'); # will append a `limit 1`
#> ['id'=>'1','name'=>'bob']
Db::rows('select * from user');
#> [['id'=>'1','name'=>'bob'], ['id'=>'2','name'=>'bill']]
Db::column('select name from user');
#> ['bob','bill']
Db::columns('select * from user');
#> [['1','bob'],[['2','bill']]
list($id, $name) = Db::enumerate('select id, name from user');
Db::column_key('id','select id, name from user');
#> ['1'=>'bob', '2'=>'bill']
# if more than 2 columns are selected, the key points to another array, ex:
# #> ['1'=>['name'=>'bob', 'gender'=>'m'], '2'=>['name'=>'bill', 'gender'=>'m']]
Db::row('user',1); # select * from user where id = 1
Db::row('user',['id'=>1]); # select * from user where id = 1
Db::insert('user',['name'=>'jill']);
Db::insert_ignore('user',['name'=>'jill']);
Db::insert_update('user',['id'=>'3','name'=>'jill']);
Db::replace('user',['id'=>'2', 'name'=>'jill']);
Db::update('user',['name'=>'jan'], ['id'=>3]);
Db::delete('user',1);
Db::delete('user',['id'=>1]);
Db::delete('user',['id
# `>` is used
Db::row('user', ['id
$pdo_statement = $db->exec(['select * from user where id = :id',[':id'=>1]])
$pdo_statement = $db->exec('select * from','user where id = :id',[':id'=>1],'and id = :id2',[':id2'=>1] );
$pdo_statement = $db->exec(['select * from user where id = :id',[':id'=>1]])
$db->as_row($pdo_statement);
$db->as_rows($pdo_statement);
$db->as_value($pdo_statement);
sql
SELECT * FROM `x` WHERE
`id` > 10 AND
`name` is not null AND
`disabled` is null AND
`gender` = 'm' AND
`last_login` = DATE()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.