PHP code example of lite-view / sql
1. Go to this page and download the library: Download lite-view/sql 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/ */
lite-view / sql example snippets
use LiteView\SQL\Crud;
L\Config::set('mysql', [
"driver" => "mysql",
"host" => "127.0.0.1",
"port" => 3306,
"username" => "test",
"password" => "Test.666",
"dbname" => "test",
"charset" => "utf8mb4",
"prepares" => true
]);
// 配置方式二
//const MYSQL_CONNECTION = [
// 'mysql' => [
// "driver" => "mysql",
// "host" => "127.0.0.1",
// "port" => 3306,
// "username" => "test",
// "password" => "Test.666",
// "dbname" => "test",
// "charset" => "utf8mb4",
// "prepares" => true
// ]
//];
$r = \LiteView\SQL\Connect::db()->query('select version()')->fetch();
print_r($r);
$r = Crud::db()->updateOrInsert('users', ['id' => 11]);
print_r($r);
$r = Crud::db()->update('users', ['name' => time()], 'id = 11');
print_r($r);
$r = Crud::db()->insert('users', ['name' => 'xxx']);
print_r($r);
//
$r = Crud::db()->select('users', '1')->prep()->all();
print_r($r);
$r = Crud::db()->select('users', '1')->prep()->one();
print_r($r);
$r = Crud::db()->select('users', '1')->prep()->paginate(10);
print_r($r);