Coder Social home page Coder Social logo

mysql-utils's Introduction

MySQL-Utils

基于Medoo的单例类,没有对Medoo做任何修改,仅为了方便使用而加了层单例壳。

  1. 使用setConfig($name, $config)加载配置到静态属性$configs中,$name为连接名,$config为连接选项参数
  2. 使用getInstance($name)获取指定连接名$name\Medoo\Medoo实例
  3. 获取的即为Medoo实例,直接使用即可
$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();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.