1. Go to this page and download the library: Download be/db4 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/ */
// 返回用户信息对象
$user = $db->getObject('SELECT * FROM user WHERE id=1');
// 返回用户信息数组
$user = $db->getArray('SELECT * FROM user WHERE id=1');
// 返回符合条件的所有用户信息, 对象数组
$users = $db->getObjects('SELECT * FROM user WHERE age=18');
// 返回符合条件的所有用户信息, 二维数组
$users = $db->getArrays('SELECT * FROM user WHERE age=18');
// 返回单个值
$count = $db->getValue('SELECT COUNT(*) FROM user WHERE age=18');
// 返回多个值,数组
$names = $db->getValues('SELECT name FROM user WHERE age=18');
// 返回键值对, 带键名的数组(id 作为键名,name 作为值)
$idNameKeyValues = $db->getKeyValues('SELECT id, name FROM user WHERE age=18');
// 返回键值对, 带键名的数组(id 作为键名,用户信息数组 作为值)
$idUserKeyArrays = $db->getKeyArrays('SELECT id, name, age FROM user WHERE age=18');
// 返回键值对, 带键名的数组(id 作为键名,用户信息对像 作为值)
$idUserKeyObjects = $db->getKeyValues('SELECT id, name, age FROM user WHERE age=18');
// 以迭代器形式返回符合条件的所有用户信息,对象数组,用作处理大量数据,消耗较少内存
$users = $db->getYieldObjects('SELECT * FROM user WHERE age=18');
// 以迭代器形式返回符合条件的用户信息,二维数组,用作处理大量数据,消耗较少内存
$users = $db->getYieldArrays('SELECT * FROM user WHERE age=18');
$users = $db->getObjects('SELECT * FROM user WHERE age=?', [18]);
$users = $db->getObjects('SELECT * FROM user WHERE age>=? AND age<=?', [18, 25]);
$users = $db->getObjects('SELECT * FROM user WHERE name=?', ['abc']);
$users = $db->getObjects('SELECT * FROM user WHERE name=? AND age=?', ['abc', 18]);