php mysql操作问题
数据库链接成功返回,在执行mysqli_query时抛出异常,求解!
错误信息:
fatal error: uncaught exception 'db_exception' with message '更新失败:no database selected' in...
php脚本:
query($sql);
var_dump($data);
?>
数据库单例成功返回
class dbfactory {
private static $db = array();
public static function getinstance($dbkey = 'default') {
if (array_key_exists($dbkey, self::$db)) {
return self::$db[$dbkey];
} else {
$newdb = new mysqlidb($dbkey);
if ($newdb->connect()) {
self::$db[$dbkey] = $newdb;
return $newdb;
} else {
return false;
}
}
}
}
$qrs = mysqli_query($this->_conn, $sql, $quick ? mysqli_use_result : mysqli_store_result);
if (!$qrs) {
throw new db_exception('查询失败:' . mysqli_error($this->_conn));
} else {
return $qrs;
}
------解决方案--------------------
错误信息很明确:no database selected
没有选择数据库