1. Go to this page and download the library: Download krugozor/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/ */
krugozor / database example snippets
$result = $db->query(
"SELECT * FROM `users` WHERE `name` = '?s' AND `age` = ?i",
"d'Artagnan", 41
);
// Previously, before each request to the DBMS, we did
// something like this (and many people still don't do it):
$id = (int) $_POST['id'];
$value = mysqli_real_escape_string($mysql, $_POST['value']);
$result = mysqli_query($mysql, "SELECT * FROM `t` WHERE `f1` = '$value' AND `f2` = $id");
$db->query(
"INSERT INTO `t` SET `name` = '?s', `flag` = ?i",
null, false
);
// set strict mode
$db->setTypeMode(Mysql::MODE_STRICT);
// this expression will not be executed, an exception will be thrown:
// attempt to specify a value of type "integer" for placeholder of type "double" in query template "SELECT ?i"
$db->query('SELECT ?i', 55.5);
$db->query(
'SELECT * FROM `users` WHERE `id` = ?i', 123
);
$db->query(
'SELECT * FROM `prices` WHERE `cost` IN (?d, ?d)',
12.56, '12.33'
);
$db->query(
'SELECT "?s"',
"You are all fools, and I am d'Artagnan!"
);
$db->query('SELECT "?S"', '% _');
$db->query('SELECT ?n', 123);
$db->query(
'INSERT INTO `test` SET ?Ai',
['first' => '123', 'second' => 456]
);
$db->query(
'SELECT * FROM `test` WHERE `id` IN (?ai)',
[123, 456]
);
$db->query(
'INSERT INTO `users` SET ?A[?i, "?s"]',
['age' => 41, 'name' => "d'Artagnan"]
);
$db->query(
'SELECT * FROM `users` WHERE `name` IN (?a["?s", "?s"])',
['Daniel O"Neill', "d'Artagnan"]
);
$db->query(
'SELECT ?f FROM ?f',
'name',
'database.table_name'
);