global 与 $GLOBALS 的应用 【2011-9-2】

在封装数据的时候,使用$GLOBALS['db']能够很好的体现出$GLOBALS和global的区别

使用范例

页面:function.inc.php

函数:

 function getCategory(){
 $sql = "select * from hy_b_info";
 $GLOBALS['db']->query($sql);
 $infoArr = $GLOBALS['db']->get_data();
 return $infoArr;
}

视图使用

require_once('includeFiles.php');

/*

*这里new一个数据库对象 

*include_once(CFG_LIB_DIR.'mysqldb.inc.php');
 *$db = new mysqldb();

*/

require_once('function.inc.php');

$returnArr = getCategory();

 

posted @ 2011-09-02 11:02  Falling Leaves  阅读(171)  评论(0编辑  收藏  举报