PHPCMS常用函數[二次開發用]

常用函數 , 打開include/global.func.php,下面存放一些公共函數

view plaincopy to clipboardprint?
function str_charset($in_charset, $out_charset, $str_or_arr) //轉換字符串或者數組的編碼  
function set_cookie($var, $value = '', $time = 0) //設置cookie  
function get_cookie($var) //取得cookie  
function menu($parentid, $code = '') //獲取菜單  
function is_ie() //判斷當前瀏覽器是否爲IE  
function is_date($ymd, $sep='-') //檢查日期的合法性  
function is_email($email) //驗證Email  
function file_down($filepath, $filename = '') //下載函數  
function ip() //取得IP地址  
function str_cut($string, $length, $dot = '...') //截取字符串  
function cache_read($file, $path = '', $iscachevar = 0) //讀取緩存  
function cache_write($file, $array, $path = '') //寫緩存  
function cache_delete($file, $path = '') //刪除緩存文件  
function string2array($data) //把字符串轉化成數組  
function array2string($data, $isformdata = 1) //把數組轉換成字符串  
function subarea($parentid = 0) //取得地區  
function subtype($module = 'phpcms') //取得模塊的分類  
function thumb($imgurl, $width = 100, $height = 100 ,$autocut = 1) //生成縮略圖  
function get_sql_catid($catid) //取得$catid的所有子欄目ID  
function get_sql_in($string, $s = ' ') //創建一個in 子句  
function pages($total, $page = 1, $perpage = 20, $urlrule = '', $array = array(), $catid = 0) //分頁函數  
function showmessage($msg, $url_forward = 'goback', $ms = 1250, $direct = 0) //創建提示信息  
function load($file, $module = 'phpcms', $dir = '', $isinit = 1) //包含一個類文件(如同:include_once),同時返回一個對象  
function areaname($areaid) //返回$areaid 對應的地區名字  
function username($userid) //取得用戶名  
function userid($username) //取得用戶id
function str_charset($in_charset, $out_charset, $str_or_arr) //轉換字符串或者數組的編碼
function set_cookie($var, $value = '', $time = 0) //設置cookie
function get_cookie($var) //取得cookie
function menu($parentid, $code = '') //獲取菜單
function is_ie() //判斷當前瀏覽器是否爲IE
function is_date($ymd, $sep='-') //檢查日期的合法性
function is_email($email) //驗證Email
function file_down($filepath, $filename = '') //下載函數
function ip() //取得IP地址
function str_cut($string, $length, $dot = '...') //截取字符串
function cache_read($file, $path = '', $iscachevar = 0) //讀取緩存
function cache_write($file, $array, $path = '') //寫緩存
function cache_delete($file, $path = '') //刪除緩存文件
function string2array($data) //把字符串轉化成數組
function array2string($data, $isformdata = 1) //把數組轉換成字符串
function subarea($parentid = 0) //取得地區
function subtype($module = 'phpcms') //取得模塊的分類
function thumb($imgurl, $width = 100, $height = 100 ,$autocut = 1) //生成縮略圖
function get_sql_catid($catid) //取得$catid的所有子欄目ID
function get_sql_in($string, $s = ' ') //創建一個in 子句
function pages($total, $page = 1, $perpage = 20, $urlrule = '', $array = array(), $catid = 0) //分頁函數
function showmessage($msg, $url_forward = 'goback', $ms = 1250, $direct = 0) //創建提示信息
function load($file, $module = 'phpcms', $dir = '', $isinit = 1) //包含一個類文件(如同:include_once),同時返回一個對象
function areaname($areaid) //返回$areaid 對應的地區名字
function username($userid) //取得用戶名
function userid($username) //取得用戶id

數據庫類,打開include/db_mysql.class.php
系統會自動載入 db_mysql.class.php 文件,並用進行初始化數據庫連接,因此在工程所有文件中均不需要單獨初始化這個類,可直接用$db 進行操作,爲了防止錯誤,操作完後不必關閉數據庫

常用的方法:
1、執行一個非查詢類型的SQL語句,如 insert 、create 、update 等
$db->query($sql);
返回值爲是否執行成功。
2、對數據庫進行插入操作
$db->insert($tablename, $array);//$tablename 表名,$array 字段名與值的對應 數組
返回值爲是否執行成功。
3、執行一條更新操作
$db->update($tablename, $array, $where);// $tablename 表名, $array 字段名與值的對應 數組, $where 更新條件
返回值爲是否執行成功。
4、返回單條記錄
$db->get_one($sql);
5、執行條件查詢語句
$result = $db->query($sql);
while($r = $db->fetch_array($result))
{
}
等效於:
$arr = $db->select($sql);
6、重新選擇要操作的數據庫
$db->select_db($tablename);
7、獲取上一個插入的自動遞增主鍵id值
$db->insert_id();
8、獲得MySql的版本號
$db->version();
9、析放某查詢的資源
$db->free_result($result);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章