PHP code example of naukakodu / php-mysql-connection
1. Go to this page and download the library: Download naukakodu/php-mysql-connection 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/ */
// Fetching all rows
$users = $db->fetchAll("SELECT * FROM users WHERE status = ?", ['active']);
// Fetching a single row
$user = $db->fetch("SELECT * FROM users WHERE id = ?", [1]);
$userId = $db->insert(
"INSERT INTO users (name, email, created_at) VALUES (?, ?, NOW())",
['John Smith', '[email protected]']
);
echo "Added user with ID: " . $userId;
$db->query("UPDATE users SET status = ? WHERE id = ?", ['inactive', 5]);
$pdo = $db->getConnection();
// ...
$db = new Database('localhost', 'database_name', 'username', 'password', 'utf8');
$database = new Database('localhost', 'database_name', 'username', 'password');
$queryBuilder = $database->getQueryBuilder();