user类,有下面这么个函数,获取用户的信息.class user
{
public function GetUserInfo($user)
{
$return = array();
$this->rDbConn->mSql = "select * from USER where uid = '" . addslashes($user) . "'";
$this->rDbConn->CreateConn();
$this->rDbConn->GetResult();
if ($this->rDbConn->GetRowNum()>0)
{
if ($this->rDbConn->GetRow())
{
$return = $this->rDbConn->mRow;
}
}
$this->rDbConn->Close();
return $return;
}
}调用的时候如下:
$class_user = new User($db);
$userInfo = $class_user->GetUserInfo($user);
在服务器和本地机器上代码是一样,但是在服务器上获取到是一个字符串,可以直接echo,但在本地却是一个stdClass对象,如果直接输出,或者像array那样下标访问,就会提示类似如下的信息:
fatal error: Object of class stdClass could not be converted to string实在很奇怪,找不到原因,代码是一样的,因为是复制的;数据库是MSSQL2005,服务器端是用备份还原的;web环境是用的wamp,
php版本5.2.11,apache版本2.2.11.
不知道是不是配置文件不同的关系?能想到的暂时只有这个了.
还请各位大侠帮忙,分数不多..
{
public function GetUserInfo($user)
{
$return = array();
$this->rDbConn->mSql = "select * from USER where uid = '" . addslashes($user) . "'";
$this->rDbConn->CreateConn();
$this->rDbConn->GetResult();
if ($this->rDbConn->GetRowNum()>0)
{
if ($this->rDbConn->GetRow())
{
$return = $this->rDbConn->mRow;
}
}
$this->rDbConn->Close();
return $return;
}
}调用的时候如下:
$class_user = new User($db);
$userInfo = $class_user->GetUserInfo($user);
在服务器和本地机器上代码是一样,但是在服务器上获取到是一个字符串,可以直接echo,但在本地却是一个stdClass对象,如果直接输出,或者像array那样下标访问,就会提示类似如下的信息:
fatal error: Object of class stdClass could not be converted to string实在很奇怪,找不到原因,代码是一样的,因为是复制的;数据库是MSSQL2005,服务器端是用备份还原的;web环境是用的wamp,
php版本5.2.11,apache版本2.2.11.
不知道是不是配置文件不同的关系?能想到的暂时只有这个了.
还请各位大侠帮忙,分数不多..
先
print_r($userInfo);
看看都是些什么
------Object of class说明这个是个对象,打印对象当然是会报错的,打印他的属性就可以
user类中GetUserInfo的定义
public function GetUserInfo($user)
{
$return = array();
$this->rDbConn->mSql = "select * from USER where uid = '" . addslashes($user) . "'";
$this->rDbConn->CreateConn();
$this->rDbConn->GetResult();
if ($this->rDbConn->GetRowNum()>0)
{
if ($this->rDbConn->GetRow())
{
$return = $this->rDbConn->mRow;
}
}
$this->rDbConn->Close();
return $return;
}下面是调用
$class_user = new User($db);
$userInfo = $class_user->GetUserInfo($_SESSION['loginfo']['userid']);
$smarty->assign('regdate',$userInfo['reg_date']);最后一行就出错提示
Catchable fatal error: Object of class stdClass could not be converted to string
但在服务器上就显示正常,楼上的方法也试过了,还是一样的问题.
看一下,你的user类是否被引用进来了。
按ctrl+左键。。看看能不能找到相关描述和进入相应代码。
这个错误最有可能的是你的,$_SESSION['loginfo']['userid']不存在。echo $_SESSION['loginfo']['userid'];看看有没?
应该跟这个的配置有点关系吧。。
这些东西对于调试很有用:
var_dump
var_export
debug_print_backtrace
var_dump 下$userInfo 看看是什么东西。 另外推荐一个
PHP调试技术手册
http://www.laruence.com/2010/06/21/1608.html
session在使用的时候应该是要先打开的.用start()方法.我记得是这样.
你打开了吗??
还有你最好调查一下$this->rDbConn->mRow这个东西返回的是什么.确定是字符串或数组吗??