Inheriting this class would require reloading connection info.
public static getInstance ( ) : MysqliDb | ||
return | MysqliDb | Returns the current instance. |
public function SetProperties($lang, $id, $name, $description) { if ($who = Registry::getInstance()->getUser()) { if (isset($who['user_id']) && $who['user_id']) { $this_prop = $this->ListProperties(array($lang), array(), array($id)); $db = MysqliDb::getInstance(); if ($this_prop) { $data = array($this->_propertyType => $name, 'description' => $description, 'who_last_update' => $who['user_id']); if ($db->where($this->_propertyType . '_id', $id)->where('language', $lang)->update($this->_propertyType . '_data', $data)) { return $name; } else { return false; } } else { $data = array($this->_propertyType . '_id' => $id, 'language' => $lang, $this->_propertyType => $name, 'description' => $description, 'who_last_update' => $who['user_id']); if ($db->insert($this->_propertyType . '_data', $data)) { return true; } else { return false; } } } else { return false; } } else { return false; } }
function showzx() { $zid = req('zid'); $start = req('start', 0); $perpage = req('perpage', 0); if ($start < 0) { $start = 0; } if (empty($perpage)) { $perpage = 30; } if (empty($zid)) { showjson('zid_not_exist'); } $db = MysqliDb::getInstance(); $data = $db->rawQueryOne("SELECT z.*, u.username FROM zixun z LEFT JOIN users u ON z.uid=u.uid WHERE z.zid='{$zid}'"); if ($db->count > 0) { $db->where("zid", $zid); $stats = $db->getOne("comment", "count(*) as cnt"); $data['total'] = $stats['cnt']; //if($start>=$data['total']) $start=0; $comment = $db->rawQuery("SELECT c.*,s.username FROM comment c LEFT JOIN users s ON c.uid=s.uid WHERE c.zid='{$zid}' ORDER BY c.cid LIMIT {$start},{$perpage}"); $data['count'] = $db->count; $data['comment'] = $comment; showjson('do_success', 0, array("zixun" => $data)); } showjson('show_error'); }
public function __construct() { /** @var array $db */ include_once 'config.php'; require_once 'PHP-MySQLi-Database-Class-master/MysqliDb.php'; new MysqliDb($db); $this->db_instance = MysqliDb::getInstance(); $this->db_config = $db; }
/** * constructor * * @param string $type tipo de datamanager a ser incializado * * inicializa o objeto de log e de bd * inicializa o vetor de dados nulo de acordo com o tipo */ function __construct($type) { $this->db = MysqliDb::getInstance(); $this->log = Log::getInstance(); //tipo de dado valido pra iniciar if (array_key_exists($type, $this->_validFields)) { $this->type = $type; foreach ($this->_validFields[$this->type] as $key => $value) { $this->setField($key, null); } } }
/** * Created by PhpStorm. * User: André * Date: 01/04/2015 * Time: 13:57 */ function buildOutput($data, $debug = false) { $log = Log::getInstance(); $db = MysqliDb::getInstance(); $output = array(); if ($log->countErrors() > 0) { $errors = $log->getErrors(); } $output = $data; if (isset($errors) && sizeof($errors) > 0) { $output['_ERROR_'] = $errors; } if ($debug == 'true') { $output['_DEBUG_'] = $log->getLogs(); } echo json_encode($output, JSON_PRETTY_PRINT); }
function login() { $password = req('password'); $username = req('username'); $db = MysqliDb::getInstance(); if ($password && $username) { $db->where('username', $username); if ($user = $db->getOne('users')) { if ($user['password'] == $password) { $auth = authcode("{$user['password']}\t{$user['uid']}", 'ENCODE'); showjson('do_success', 0, array("auth" => rawurlencode($auth))); } showjson('password_error'); } } showjson('login_error'); }
function checkauth() { global $_SGLOBAL; $auth = req('auth'); if ($auth) { $db = MysqliDb::getInstance(); @(list($password, $uid) = explode("\t", authcode($auth, 'DECODE'))); $_SGLOBAL['uid'] = intval($uid); if ($password && $_SGLOBAL['uid']) { $db->where('uid', $_SGLOBAL['uid']); if ($user = $db->getOne('users')) { if ($user['password'] == $password) { $_SGLOBAL['usertype'] = $user['usertype']; $_SGLOBAL['username'] = $user['username']; return; } } } } showjson('to_login'); }
function comment() { global $_SGLOBAL; checkauth(); //验证登陆 $op = req('op'); $db = MysqliDb::getInstance(); if ($op == 'add') { $setarr = array('uid' => $_SGLOBAL['uid']); $setarr['message'] = req('message'); $setarr['zid'] = req('zid', 0); if ($setarr['message'] && $setarr['zid']) { $id = $db->insert('comment', $setarr); //插入数据 if ($id) { showjson('do_success', 0, array("cid" => $id)); } showjson('submit_comment_error'); } showjson('zid_or_message_can_not_empty'); } elseif ($op == 'del') { $cid = req('cid', 0); if (empty($cid)) { showjson('non_normal_operation'); } $db->where('cid', $cid); if ($_SGLOBAL['usertype'] == 1) { //是否管理员 } else { $db->where('uid', $_SGLOBAL['uid']); } $result = $db->delete('comment'); //删除评论 if ($result) { showjson('do_success', 0); } showjson('comment_not_exist'); } }
/** * @param array $data Data to preload on object creation */ public function __construct($data = null) { $this->db = MysqliDb::getInstance(); if (empty($this->dbTable)) { $this->dbTable = get_class($this); } if ($data) { $this->data = $data; } }
/** * @param array $data Data to preload on object creation */ public function __construct($data = null) { $this->db = MysqliDb::getInstance(); if ($data) { $this->data = $data; } }