我写了个类,但是在function 里用不了 本帖最后由 jeiryc 于 2009-12-31 15:42:44 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 global $db 下。在head.php里 把 include_once 改成 include 试试 select() 你写成函数,我真汗。 你把,$db=new DB(dbhost,dbuser,dbpass,dbname);产生的$db 传参传进去吧,function load_class($conditions1,&$db){ //include_once 'conn.php'; include_once('feipicadmin/db.php');//类文件 $result = $db->select("select channel_folder from feipic_chennel where channel_id = $conditions1");for($i=0;$i<count($result);$i++){echo = $result[$i][0];} //} load_class($conditions1=2); load_class函数内要global $db;或者$GLOBALS['db']->select 上面那个调用的时候少传了一个参数哈,代码说话demo<?phpclass test{ function print_echo(){ echo 'right'; }}$db = new test();function test2(&$db) //把对象传进去{ $db->print_echo();}test2(&$db); //调用?> php 页面长时间未操作 如何重新登录(已知道登录的时间放入session) php使用cookie undefined index错误 在看Wordpress的模板的时候看到"__("不知道是啥意思? Incorrect string value: '\xBC\xD3\xCB\xD9\xD2\xB3...' 无语的错误 推荐个调查程序 求教关于filter机制的说明 PHP的数据库链接对象可以用在函数中吗 有没有人做过类似网易的上传大包图片程序 php是否有为图片加水印的组件啊 关于读文件的一个问题(高分) 关于给变量赋布尔值的疑问 高手来解决下看看什么问题
产生的$db 传参传进去吧,function load_class($conditions1,&$db){
//include_once 'conn.php';
include_once('feipicadmin/db.php');//类文件
$result = $db->select("select channel_folder from feipic_chennel where channel_id = $conditions1");
for($i=0;$i<count($result);$i++){
echo = $result[$i][0];
}
//
}
load_class($conditions1=2);
<?php
class test{
function print_echo(){
echo 'right';
}
}
$db = new test();
function test2(&$db) //把对象传进去
{
$db->print_echo();
}
test2(&$db); //调用
?>