1. Go to this page and download the library: Download v10086/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/ */
v10086 / db example snippets
//设置配置信息
\v10086\DB::$config=[
'default'=>[
'dsn'=>'mysql:127.0.0.1;dbname=app;charset=utf8mb4;collation=utf8mb4_unicode_ci',
'user'=>'dbuser',
'password'=>'dbpass'
],
'other'=>[
'dsn'=>'mysql:127.0.0.1;dbname=other_app;charset=utf8mb4;collation=utf8mb4_unicode_ci',
'user'=>'other_dbuser',
'password'=>'other_dbpass'
],
];
//默认default 可设置为其他配置
\v10086\DB::connection('default');
//查询单个用户
$user = \v10086\DB::exec('select * from user where id=?',[10086])->fetch();
//查询多个用户 二维数组
$user_list = \v10086\DB::exec('select * from user where id > ?',[100])->fetchAll();
//查询单字段值
$username = \v10086\DB::exec('select username from user where id=?',[10086])->fetch(\PDO::FETCH_COLUMN, 0);
//用户编号列表 一维数组
$uid_list = \v10086\DB::exec('select id from user ')->fetchAll(\PDO::FETCH_COLUMN, 0);
//新增数据
$user_add['username']='zhongbo';
$user_add['created_at']= time();
$user_add['updated_at']= time();
\v10086\DB::insert('user', $user_add);
//获取插入后的数据编号
$uid=\v10086\DB::lastInsertId();
//更新数据
$upd['username']='钟波';
\v10086\DB::update('user', $upd,'id =? ',[$uid]);
//删除数据
\v10086\DB::exec('delete from user where id = ? ',[$uid]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.