mradang/mysql

v1.1 2018-10-06 06:26 UTC

This package is auto-updated.

Last update: 2024-11-05 20:54:39 UTC


README

安装

composer require mradang/MySQL

使用

// 初始化
$config = [
    'host' => 'localhost',
    'port' => '3306',
    'database' => 'test',
    'username' => 'test',
    'password' => 'test',
    'charset' => 'utf8',
];
$db = new \mradang\MySQL\MySQL($config);

// 插入
$id = $db->insert_kv('logs', [
    'msg' => 'test',
    'created_at' => time(),
]);

// 更新
$sql = 'update logs set msg = ? where id = ?';
$rows = $db->update($sql, ['test2', 1]);

// 删除
$sql = 'delete from logs where id = ?';
$rows = $db->delete($sql, [2]);

// 查询
$sql = 'select * from logs order by id desc';
$rs = $db->select($sql, [], 1, 2);

// 单条查询
$sql = 'select * from logs where id = ?';
$log = $db->fetch($sql, [1]);

// 取值
$sql = 'select msg from logs where id = ?';
$msg = $db->value($sql, [1]);