PHP code example of ruesin / mysql

1. Go to this page and download the library: Download ruesin/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/ */

    

ruesin / mysql example snippets


$configs = [
    'blog' => [
        'driver' => 'mysql',
        'host' => '127.0.0.1',
        'database' => 'blog',
        'username' => 'root',
        'password' => 'root',
        'port' => '3306',
        'retry_exception' => [
            // 'MySQL server has gone away'
        ]
    ],
    'web' => [
        'driver' => 'mysql',
        'host' => '127.0.0.1',
        'database' => 'web',
        'username' => 'root',
        'password' => 'root',
        'port' => '3306'
    ],
];
//加载配置到静态属性
foreach ($configs as $key => $config) {
    \Ruesin\Utils\MySQL::setConfig($key, $config);
}

//获取连接实例
$mysql = \Ruesin\Utils\MySQL::getInstance('blog');

//执行查询
$mysql->query("SELECT sleep(30);");
$mysql->query("SELECT sleep(10);");
\Ruesin\Utils\MySQL::getInstance('blog')->query("SELECT sleep(5);");

//关闭连接
\Ruesin\Utils\MySQL::close('blog');

//清除所有连接
\Ruesin\Utils\MySQL::clear();