php mysql 数据库框架_超轻量级PHP SQL数据库框架

/**

* ! Medoo 0.8.5 - Copyright 2013, Angel Lai - MIT license - http://medoo.in

*/

class medoo{

protected $database_type = 'mysql';

// For MySQL, MSSQL, Sybase

protected $server = 'localhost';

protected $username = 'username';

protected $password = 'password';

// For SQLite

protected $database_file = '';

// Optional

protected $charset = 'utf8';

protected $database_name = '';

protected $option = array();

public function __construct($options){

try{

$type = strtolower($this -> database_type);

if(is_string($options)){

if($type == 'sqlite'){

$this -> database_file = $options;

}else{

$this -> database_name = $options;

}

}else{

foreach($options as $option => $value){

$this -> $option = $value;

}

}

$type = strtolower($this -> database_type);

switch($type){

case 'mysql':case 'pgsql':$this -> pdo = new PDO($type . ':host=' . $this -> server . ';dbname=' . $this -> database_name, $this -> username, $this -> password, $this -> option);

break;

case 'mssql':case 'sybase':$this -> pdo = new PDO($type . ':host=' . $this -> server . ';dbname=' . $this -> database_name . ',' . $this -> username . ',' . $this -> password, $this -> option);

break;

case 'sqlite':$this -> pdo = new PDO($type . ':' . $this -> database_file, $this -> option);

break;

}

$this -> pdo -> exec('SET NAMES \'' . $this -> charset . '\'');

}

catch(PDOException$e){

echo $e -> getMessage();

}

}

public function query($query){

$this -> queryString = $query;

return $this -> pdo -> query($query);

}

public function exec($query){

$this -> queryString = $query;

return $this -> pdo -> exec($query);

}

public function quote($string){

return $this -> pdo -> quote($string);

}

protected function array_quote($array){

$temp = array();

foreach($array as $value){

$temp[] = is_int($value)?$value:$this -> pdo -> quote($value);

}

return implode($temp, ',');

}

protected function inner_conjunct($data, $conjunctor, $outer_conjunctor){

$haystack = array();

foreach($data as $value){

$haystack[] = '(' . $this -> data_implode($value, $conjunctor) . ')';

}

return implode($outer_conjunctor . ' ', $haystack);

}

protected function data_implode($data, $conjunctor, $outer_conjunctor = null){

$wheres = array();

foreach($data as $key => $value){

if(($key == 'AND' || $key == 'OR') && is_array($value)){

$wheres[] = 0 !== count(array_diff_key($value, array_keys(array_keys($value))))?'(' . $this -> data_implode($valu

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值