1. Go to this page and download the library: Download cloudtay/ripple-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/ */
cloudtay / ripple-database example snippets
declare(strict_types=1);
= "mysql:host=127.0.0.1;port=3306;dbname=test_db;charset=utf8mb4";
$pdo = new PDO($dsn, 'root', '123456');
// 创建表
$pdo->exec("CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) UNIQUE
)");
// 预处理语句
$stmt = $pdo->prepare("INSERT INTO users (name, email) VALUES (?, ?)");
$stmt->execute(['Alice', '[email protected]']);
// 查询数据
$result = $pdo->query("SELECT * FROM users WHERE name = 'Alice'")->fetch();
echo "User: {$result['name']} - {$result['email']}\n";