1. Go to this page and download the library: Download eb/mysql 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/ */
$db = Mysql\Client::init([
'user' => 'username',
'password' => 'password',
'defaultDb' => 'Sakila',
'charset' => 'utf8',
'lazy' => true,
]);
~~~
Если опция `'lazy'` установлена в `true`, то подключение к базе данных создаётся не сразу, а при первом запросе.
### Запрос и получение данных
~~~php
$result = $db->query('
select * from `Book`
where `author` = :author
', [':author' => 'Мартин Фаулер']);
while ($row = $result->row()) {
echo $row['title'], "\n";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.