PHP code example of houdunwang / db

1. Go to this page and download the library: Download houdunwang/db 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/ */

    

houdunwang / db example snippets


Db::table('user')-> insertGetId(['username'=>'向军','qq'=>'2300071698']);

Db::table('user')->where("id",1)->update(['username'=>'后盾网']);
//数组数据会过滤掉非法字段

$db = Db::table( 'news' );
$db->insert( [ 'title' => '后盾网' ] );
echo $db->getInsertId();

$db = Db::table( 'news' );
$db->update( [ 'title' => '后盾人' ] );
echo $db->getAffectedRow();

Db::table('user')->lists('username');

//满足条件记录的所有username字段
[
    [0] => admin
    [1] => hdxj
]

Db::table('user')->lists('id,username'); 

//id 字段做为键名使用
[
    [1] => admin
    [2] => hdxj
]

Db::table('user')->whereRaw('age > ? and username =?', [1,'admin'])->get();

$users = Db::table( 'user' )->paginate(3);
foreach ( $users as $f ) {
	p( $f['username'] );
}
//显示页码链接
dd($users->links());