PHP code example of ziyoren / database

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

    

ziyoren / database example snippets




use ziyoren\Database\BaseModel; // swoole(支持数据库连接池)
//use ziyoren\Database\PDO;       // 传统的php-fpm 无连接池

//For database configuration, see ziyoren\Database\DbConfig.php
$db = new BaseModel(); //swoole模式下使用
//$db = new PDO(); //php-fpm模式下使用

$db->insert('account', [
    'user_name' => 'foo',
    'email' => '[email protected]'
]);

$data = $db->select('account', [
    'user_name',
    'email'
], [
    'user_id' => 50
]);

echo json_encode($data);



use ziyoren\Database\BaseRedis;

//For Redis configuration, see /config/redis.php
$redis = new BaseRedis();
$redis->set('key', 'value');
$rst = $redis->get('key');

echo $rst; //value