Download the PHP package tekintian/mydb without Composer
On this page you can find all versions of the php package tekintian/mydb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tekintian/mydb
More information about tekintian/mydb
Files in tekintian/mydb
Package mydb
Short Description 安全,高新能的PHP mysql/mysqli数据库驱动类,支持主从,分库分表,sql注入防御等,High efficiently mysql mysqli driver, support master slave, muiti table data etc.
License BSD-4-Clause
Informations about the package mydb
支持主从,分库分表的高效安全的mysql/mysqli数据库驱动封装
使用方法
composer require tekintian\mydb
// 使用自动加载
require_once __DIR__ . '/vendor/autoload.php';
// 利用类继承给类起个简短的别名
class DB extends tekintian\mydb\MyDb {}
// 获取MyDb中的 $db 对象并引用赋值给 $db
$db = & DB::object();
$dbversion = $db->version(); // 使用 $db对象获取mysql版本
// DB静态方法查询数据
// 使用 DB::table('common_district') 来自动加上配置的数据库表前缀
$list = DB::fetch_all("select * from " . DB::table('common_district') . " limit 100");
print_r($list);
使用示例
pp($list);
// 使用 DB::table('common_district') 来自动加上配置的数据库表前缀
$list = DB::fetch_all("select * from " . DB::table('common_district') . " limit 100");
pp($list);
// 复杂查询示例
// $query = DB::query("SELECT me.id, me.uid, me.medalid, me.dateline, me.expiration, mf.medals
// FROM " . DB::table('forum_medallog') . " me
// LEFT JOIN " . DB::table('common_member_field_forum') . " mf USING (uid)
// WHERE id IN ($ids)");
// while ($vv = DB::fetch($query)) {
// }
// 更多的查询方法,可参考 dz的源码
配置示例
/**
* 数据库配置文件
* @Author: tekin
* @Date: 2020-06-12 12:13:29
* @Last Modified 2020-06-13
* @Last Modified time: 2020-06-13 14:00:21
*/
$_config = array();
// ---------------------------- CONFIG DB ----------------------------- //
$_config['db']['1']['dbhost'] = 'localhost';
$_config['db']['1']['dbuser'] = 'ultrax';
$_config['db']['1']['dbpw'] = 'ultraxultrax';
$_config['db']['1']['dbcharset'] = 'utf8';
$_config['db']['1']['pconnect'] = '0';
$_config['db']['1']['dbname'] = 'ultrax';
$_config['db']['1']['tablepre'] = 'pre_';
$_config['db']['slave'] = '';
$_config['db']['common']['slave_except_table'] = '';
// ------------- CONFIG SECURITY ------------ //
$_config['security']['querysafe']['status'] = 1;
$_config['security']['querysafe']['dfunction']['0'] = 'load_file';
$_config['security']['querysafe']['dfunction']['1'] = 'hex';
$_config['security']['querysafe']['dfunction']['2'] = 'substring';
$_config['security']['querysafe']['dfunction']['3'] = 'if';
$_config['security']['querysafe']['dfunction']['4'] = 'ord';
$_config['security']['querysafe']['dfunction']['5'] = 'char';
$_config['security']['querysafe']['daction']['0'] = '@';
$_config['security']['querysafe']['daction']['1'] = 'intooutfile';
$_config['security']['querysafe']['daction']['2'] = 'intodumpfile';
$_config['security']['querysafe']['daction']['3'] = 'unionselect';
$_config['security']['querysafe']['daction']['4'] = '(select';
$_config['security']['querysafe']['daction']['5'] = 'unionall';
$_config['security']['querysafe']['daction']['6'] = 'uniondistinct';
$_config['security']['querysafe']['dnote']['0'] = '/*';
$_config['security']['querysafe']['dnote']['1'] = '*/';
$_config['security']['querysafe']['dnote']['2'] = '#';
$_config['security']['querysafe']['dnote']['3'] = '--';
$_config['security']['querysafe']['dnote']['4'] = '"';
$_config['security']['querysafe']['dlikehex'] = 1;
$_config['security']['querysafe']['afullnote'] = '0';
- DZ的数据库分库分表映射配置参考
for($i = 1; $i <= 100; $i++) { if(isset($this->map['forum_thread'])) { $this->map['forumthread'.$i] = $this->map['forum_thread']; } if(isset($this->map['forum_post'])) { $this->map['forumpost'.$i] = $this->map['forum_post']; } if(isset($this->map['forum_attachment']) && $i <= 10) { $this->map['forumattachment'.($i-1)] = $this->map['forum_attachment']; } } if(isset($this->map['common_member'])) { $this->map['common_member_archive'] = $this->map['common_member_count'] = $this->map['common_member_count_archive'] = $this->map['common_member_status'] = $this->map['common_member_status_archive'] = $this->map['common_member_profile'] = $this->map['common_member_profile_archive'] = $this->map['common_member_field_forum'] = $this->map['common_member_field_forum_archive'] = $this->map['common_member_field_home'] = $this->map['common_member_field_home_archive'] = $this->map['common_member_validate'] = $this->map['common_member_verify'] = $this->map['common_member_verify_info'] = $this->map['common_member']; }