# $db
## $db
默認數據庫實例
如果配置文件設置了數據庫相關的配置,則框架會自動實例化一個 DB 類。
一般不用直接使用這個變量,除非在升級,轉換需要多個連接的時候。
一般用 db\_find(), db\_find\_one(), db\_exec(), db\_count() 函數來操作數據庫。
【定義】 文件:xiunophp/xiunophp.php 大約 76 行:
```
<pre class="calibre11">```
$db = !empty($conf['db']) ? db_new($conf['db']) : NULL;
```
```
【用例】
```
<pre class="calibre11">```
<?php
$conf = include './conf.php';
include './xiunophp/xiunophp.php';
$arr = $db->find_one("SELECT * FROM bbs_user LIMIT 1");
?>
```
```
【conf.php】
```
<pre class="calibre11">```
<?php
return array (
// -------------> xiunophp 依賴的配置
'db'=>array(
'type'=>'pdo_mysql',
'pdo_mysql' => array (
'master' => array (
'host' => 'localhost',
'user' => 'root',
'password' => 'root',
'name' => 'test',
'charset' => 'utf8',
'engine'=>'myisam', // innodb
),
'slaves' => array()
)
),
'tmp_path' => './', // 可以配置為 linux 下的 /dev/shm ,通過內存緩存臨時文件
'log_path' => './'
);
?>
```
```
- XiunoPHP 入門
- 什么是 XiunoPHP?
- 關于 URL 格式
- 編碼規范
- 全局變量
- $starttime
- $time
- $conf
- $ip
- $longip
- $ajax
- $method
- $db
- $cache
- $errno
- $errstr
- 數據庫函數
- DB 配置
- db_insert()
- db_create()
- db_replace()
- db_update()
- db_delete()
- db_find_one()
- db_find()
- db_count()
- db_maxid()
- db_connect()
- db_truncate()
- db_sql_find()
- db_sql_find_one()
- db_exec()
- db_new()
- db_close()
- 緩存函數
- CACHE 配置
- cache_set()
- cache_get()
- cache_delete()
- cache_truncate()
- cache_new()
- 數組增強
- array_value()
- array_filter_empty()
- array_addslashes()
- array_stripslashes()
- array_htmlspecialchars()
- array_trim()
- array_diff_value()
- array_assoc_slice()
- arrlist_multisort()
- arrlist_cond_orderby()
- arrlist_key_values()
- arrlist_values()
- arrlist_change_key()
- arrlist_chunk()
- 雜項函數
- xn_strlen()
- xn_substr()
- xn_urlencode()
- xn_urldecode()
- xn_json_encode()
- xn_json_decode()
- xn_encrypt()
- xn_decrypt()
- xn_message()
- xn_error()
- xn_log()
- xn_txt_to_html()
- xn_rand()
- xn_is_writable()
- humandate()
- humannumber()
- humansize()
- param()
- lang()
- url()
- pagination()
- is_robot()
- http_get()
- http_post()
- https_get()
- https_post()
- http_multi_get()
- file_replace_var()
- file_get_contents_try()
- file_put_contents_try()
- in_string()
- file_ext()
- file_pre()
- file_name()
- http_url_path()
- glob_recursive()
- rmdir_recusive()
- copy_recusive()
- _GET() _POST() _COOKIE() ...