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();

*/

扫描二维码关注公众号,回复: 6630488 查看本文章

require_once('function.inc.php');

$returnArr = getCategory();

 

转载于:https://www.cnblogs.com/in-loading/archive/2011/09/02/2163479.html

猜你喜欢

转载自blog.csdn.net/weixin_33826268/article/details/93700310