PHP code example of wolkkr / mydb

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

    

wolkkr / mydb example snippets


$db_config = [
	"default" => [
		"host" => "127.0.0.1",
		"db" => "test",
		"user" => "root",
		"password" => "123456"
	 ],
	"test" => [
		"host" => "127.0.0.1",
		"db" => "test",
		"user" => "root",
		"password" => "123456"
	 ],
];



MyDB::conn();   // Соединение по умолчанию 'default'
MyDB::conn('test'); // Использование соединения 'test'
MyDB::conn(['host'=>'127.0.0.1','...']); // Прямая передача конфигурации соединения

$info = MyDB::conn()->table('test_table')->where('id',1)->select('id,name')->first();
$list = MyDB::conn('test')->table('test_table')
							->where('id',1)
    						->where('id=3')   // Условия для 'where'
							->where('id','!=',5)
							->where('id',[1,2,3]) // Условия запроса
							->orWhere('id',2) // Проверка
							->orderBy('id','desc')
							->limit(10)
							->get();
$list = MyDB::conn()->query("select * from t where id=?",[1]); // Запрос sql
$count = MyDB::conn()->table('test_table')->count(); // Получить количество

$rowCount = MyDB::conn()->table('test_table')->where('id',1)->update(['name'=>'123']);
$rowCount = MyDB::conn()->table('test_table')->update(['name'=>'123'],1);

$rowCount = MyDB::conn()->table('test_table')->where('id',1)->delete(); 
$rowCount = MyDB::conn()->table('test_table')->delete(12);

$insertId = MyDB::conn()->table('test_table')->insert(['name'=>'abc','age'=>15]);

$rowCount = MyDB::conn()->table('test_table')->insert([
                                                        ['name'=>'abc','age'=>15],
                                                        ['name'=>'abc2','age'=>20],
                                                        ]);

echo MyDB::conn()->getFullSql();