PHP code example of yonna / database
1. Go to this page and download the library: Download yonna/database 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/ */
yonna / database example snippets
DB::connect() // 默认 'default'
->table('system_data')
->field('key,value')
->in('key', $key)
->one();
DB::connect('mysql')
->table('system_data')
->field('key,value')
->in('key', $key)
->one();
DB::connect('pgsql')
->schemas('default')
->table('system_data')
->field('key,value')
->in('key', $key)
->multi();
DB::connect('mssql')
->schemas('default')
->table('system_data')
->field('key,value')
->in('key', $key)
->page();
DB::connect('sqlite')
->table('system_data')
->field('key,value')
->in('key', $key)
->count();
DB::connect('redis')->set('key', 1);
DB::connect('redis')->get('key');
DB::connect('redis')->incr('key');
DB::connect('redis')->decr('key');
DB::connect('redisCo')->set('swoole', 1);
DB::connect('redisCo')->get('swoole');
DB::connect('redisCo')->incr('swoole', 1.5);
DB::connect('redisCo')->decr('swoole', 2);
DB::connect('mysql')
->table('demo')
->equalTo('a',1)
->equalTo('b',1)
->closure('or')
->equalTo('c',1)
->equalTo('d',1)
->equalTo('e',1)
->closure('or')
->one();
DB::connect('pgsql')
->schemas('default')
->table('demo')
->equalTo('a',1)
->equalTo('b',1)
->closure('or')
->equalTo('c',1)
->equalTo('d',1)
->equalTo('e',1)
->closure('or',true)
->one();
try {
DB::connect('pgsql')->schemas('default')->table('data')->insert(['data' => 1]);
$lastId = DB::lastInsertId();
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
DB::connect()->table('demo')->equalTo('status',1)->fetchSql()->multi();