- pdo
- composer 安装
composer require ninvfeng/mysql
- 引入/vendor目录下的autoload.php
require 'vendor/autoload.php';
//配置
$config=[
'host'=>'127.0.0.1',
'port'=>3306,
'name'=>'test'
];
//推荐使用函数进行实例化,后续操作更加方便
function db($table='null') use $config{
static $_db;
if(!$_db){
$_db=new \ninvfeng\mysql($config);
}
return $_db->table($table);
}
db('user')->insert(['user'=>'ninvfeng','pass'=>'password']);
db('user')->insert(['user'=>'lvlv','pass'=>'password']);
db('user')->where(['user'=>'ninvfeng'])->delete();
db('user')->where(['user'=>'lvlv'])->update(['pass'=>'password2']);
db('user')->where(['user'=>'lvlv'])->find();
db('user')->select();
db('user')->where(['user'=>'ninvfeng'])->select();
db('user')->page(1)->select();
db('user')->field('user')->select();
db('user')->order('id desc')->select();
db('user')->join('user_info on user_info.user_id=user.id')->select();
db('user')->debug()->select();
db('user')->query("select * from user");
db('user')->trans();
db()->pdo();