错误提示:
Fatal error: Call to a member function RowCount() on a non-object in C:\Program Files\xampp\htdocs\www.caiyi.cn\userReg.php on line 164错误行代码:
162: $sql = "SELECT `user_id` FROM `user` WHERE user_name='".$user_name."' ORDER BY `user_id` DESC";163: $rs = $conn->Execute($sql);164: total = $rs->RowCount();
根据提示这个错误是使用成员函数时却没有对象,网上找了很多类似的提问,却没看到一个合适的解决方案,请问各位能帮忙解决吗??
Fatal error: Call to a member function RowCount() on a non-object in C:\Program Files\xampp\htdocs\www.caiyi.cn\userReg.php on line 164错误行代码:
162: $sql = "SELECT `user_id` FROM `user` WHERE user_name='".$user_name."' ORDER BY `user_id` DESC";163: $rs = $conn->Execute($sql);164: total = $rs->RowCount();
根据提示这个错误是使用成员函数时却没有对象,网上找了很多类似的提问,却没看到一个合适的解决方案,请问各位能帮忙解决吗??
RowCount()函数是某对象的成员函数,我觉得程序应该是正确的因为在一台机器中运行正常,我怀疑是本机的服务器环境配置问题,网上说在php.ini文件里要把全局变量设置register_globals = On 但我这样设置并重启后问题依然没变化,烦啊!谢谢楼上!还有办法吗??
再print_r($rs)
$user_name = getValue("user_name");
$user_nick =getValue("user_nick");
$pass_word = getValue("pass_word");
$pass_word_c = getValue("pass_word_c");
$pass_word_pay = getValue("pass_word_pay");
$pass_word_pay_c = getValue("pass_word_pay_c");
$user_email = getValue("user_email");
$user_truename = getValue("user_truename");
$user_idcard = getValue("user_idcard");
$user_idcard_c = getValue("user_idcard_c");
$user_bank = getValue("user_bank");
$user_bank_num = getValue("user_bank_num");
$user_sex = getValue("user_sex");
$user_birthday_y = getValue("user_birthday_y");
$user_birthday_m = getValue("user_birthday_m");
$user_birthday_d = getValue("user_birthday_d");
$user_tel = getValue("user_tel");
$user_from = getValue("user_from");
$user_activation = "1";
$user_grade = "A";switch($action){ case "reg" : // 注册 checkRandPic();
$user_name = checkLength($user_name,1,15);
$pass_word_pay = checkLength($pass_word_pay,6,10);
$user_idcard = checkLength($user_idcard,15,18,"身份证");
$user_email = checkEmail($user_email);
$user_truename = isNotNull($user_truename);
isSame($pass_word_pay,$pass_word_pay_c,"交易密码");
isSame($user_idcard,$user_idcard_c,"身份证号");
$pass_word_pay = md5($pass_word_pay);
$user_birthday = $user_birthday_y."-".$user_birthday_m;
$sql = "SELECT `user_id` FROM `user` WHERE `user_name`='".$user_name."' ORDER BY `user_id` DESC";
$rs = $conn->Execute($sql);
$total = $rs->RowCount();
if($total!=0){
errorGo("已经存在这个用户!");
} $table = "user";
$sql_f = array("user_name","user_nick","pass_word","pass_word_pay","user_email","user_truename","user_idcard","user_bank","user_bank_num","user_sex","user_birthday","user_tel","user_from");
$sql_v =
array($user_name, $user_nick, $pass_word, $pass_word_pay, $user_email, $user_truename, $user_idcard, $user_bank, $user_bank_num, $user_sex, $user_birthday, $user_tel, $user_from);
$sql = insertSQL($table,$sql_f,$sql_v);
$rs = $conn->Execute($sql); $sql = "SELECT `user_id` FROM `user` WHERE `user_name`='".$user_name."' ORDER BY `user_id` DESC";
$rs = $conn->Execute($sql); $ar = $rs->FetchRow(); $user_action = "1000001"; // 注册代码
logUserAct($user_action,"",$ar['user_id']); $logonInfo= md5($USER_V.md5($pass_word_pay)).($user_name);
setcookie("logonInfo",$logonInfo);
$conn = changeDBConn($PGSQL_III["database"],$PGSQL_III["hostname"], $PGSQL_III["username"], $PGSQL_III["password"]);
$table = "cdb_members";
$sql_f = array("username","password","email","groupid","regdate","lastvisit","lastactivity");
$sql_v =
array($user_name, $pass_word_pay, $user_email,"10",time(),time(),time());
$sql = insertSQL($table,$sql_f,$sql_v);
$rs = $conn->Execute($sql);
errorGo($ERROR_MESSAGE["useradd_OK"],"index.php"); break; //case "reg" case "checkUsername":
$sql = "SELECT `user_id` FROM `user` WHERE user_name='".$user_name."' ORDER BY `user_id` DESC";
//echo $sql;
$rs = $conn->Execute($sql);
$total = $rs->RowCount();// !!!报错行!!!!!!!!!!!!!
if($total!=0){
errorGo("已经存在这个用户!");
}else{
errorGo("用户不存在,请放心注册!");
}
break; default : $t->set_file("main","userReg.htm");
$t->set_file("Heads","Head.htm");
$t->parse("Head","Heads");
$t->set_file("LOGINs","LOGIN.htm");
$t->parse("LOGIN","LOGINs");
$t->set_file("ADs","AD.htm");
$t->parse("AD","ADs");
$t->set_file("LotteryHeads","LotteryHead.htm");
$t->parse("LotteryHead","LotteryHeads");
$t->set_file("LotteryTitles","LotteryTitle.htm");
$t->parse("LotteryTitle","LotteryTitles");
$t->set_file("Foots","Foot.htm");
$t->parse("Foot","Foots");
}
$t->pparse("OUT","main");
@$rs->Close();
@$conn->Close();---------------------------------------------------------------------------------
此页的代码就是这样的
进入此页面时是选择的case "checkUsername":下的部分该函数所在的类是这样的(里面函数很多,没有全贴):
class ADOConnection { //省略部分…… function RowCount() {
return $this->_numOfRows;
}
//省略部分……
}
print_r($conn);
print_r($rs);
echo '</pre>';164: total = $rs->RowCount();输出什么?贴出来看看
$temp = mysql_fetch_array($result);
$total = $temp[count];
楼上的楼上:
debug输出是这样的:
Debug:
ADODB_mysql Object
(
[databaseType] => mysql
[dataProvider] => mysql
[hasInsertID] => 1
[hasAffectedRows] => 1
[metaTablesSQL] => SHOW TABLES
[metaColumnsSQL] => SHOW COLUMNS FROM `%s`
[fmtTimeStamp] => 'Y-m-d H:i:s'
[hasLimit] => 1
[hasMoveFirst] => 1
[hasGenID] => 1
[isoDates] => 1
[sysDate] => CURDATE()
[sysTimeStamp] => NOW()
[hasTransactions] =>
[forceNewConnect] =>
[poorAffectedRows] => 1
[clientFlags] => 0
[substr] => substring
[nameQuote] => `
[compat323] =>
[_genIDSQL] => update %s set id=LAST_INSERT_ID(id+1);
[_genSeqSQL] => create table %s (id int not null)
[_genSeqCountSQL] => select count(*) from %s
[_genSeq2SQL] => insert into %s values (%s)
[_dropSeqSQL] => drop table %s
[database] => fb
[host] => localhost
[user] => root
[password] =>
[debug] =>
[maxblobsize] => 262144
[concat_operator] => +
[length] => length
[random] => rand()
[upperCase] => upper
[fmtDate] => 'Y-m-d'
[true] => 1
[false] => 0
[replaceQuote] => \'
[charSet] =>
[metaDatabasesSQL] =>
[uniqueOrderBy] =>
[emptyDate] =>
[emptyTimeStamp] =>
[lastInsID] =>
[hasTop] =>
[readOnly] =>
[genID] => 0
[raiseErrorFn] =>
[cacheSecs] => 3600
[memCache] =>
[memCacheHost] =>
[memCachePort] => 11211
[memCacheCompress] =>
[arrayClass] => ADORecordSet_array
[noNullStrings] =>
[numCacheHits] => 0
[numCacheMisses] => 0
[pageExecuteCountRows] => 1
[uniqueSort] =>
[leftOuter] =>
[rightOuter] =>
[ansiOuter] =>
[autoRollback] =>
[fnExecute] =>
[fnCacheExecute] =>
[blobEncodeType] =>
[rsPrefix] => ADORecordSet_
[autoCommit] => 1
[transOff] => 0
[transCnt] => 0
[fetchMode] =>
[null2null] => null
[_oldRaiseFn] =>
[_transOK] =>
[_connectionID] => Resource id #9
[_errorMsg] =>
[_errorCode] =>
[_queryID] =>
[_isPersistentConnection] =>
[_bindInputArray] =>
[_evalAll] =>
[_affected] =>
[_logsql] =>
[_transmode] =>
[databaseName] => fb
)
很多不相关的 你能看出哪里的问题么?
将sql语句放到mysql里运行看看是否正确。
{
if ($this->fnExecute) {
$fn = $this->fnExecute;
$ret =& $fn($this,$sql,$inputarr);
if (isset($ret)) return $ret;
}
if ($inputarr) {
if (!is_array($inputarr)) $inputarr = array($inputarr);
$element0 = reset($inputarr);
# is_object check because oci8 descriptors can be passed in
$array_2d = is_array($element0) && !is_object(reset($element0));
//remove extra memory copy of input -mikefedyk
unset($element0);
if (!is_array($sql) && !$this->_bindInputArray) {
$sqlarr = explode('?',$sql);
if (!$array_2d) $inputarr = array($inputarr);
foreach($inputarr as $arr) {
$sql = ''; $i = 0;
//Use each() instead of foreach to reduce memory usage -mikefedyk
while(list(, $v) = each($arr)) {
$sql .= $sqlarr[$i];
// from Ron Baldwin <ron.baldwin#sourceprose.com>
// Only quote string types
$typ = gettype($v);
if ($typ == 'string')
//New memory copy of input created here -mikefedyk
$sql .= $this->qstr($v);
else if ($typ == 'double')
$sql .= str_replace(',','.',$v); // locales fix so 1.1 does not get converted to 1,1
else if ($typ == 'boolean')
$sql .= $v ? $this->true : $this->false;
else if ($typ == 'object') {
if (method_exists($v, '__toString')) $sql .= $this->qstr($v->__toString());
else $sql .= $this->qstr((string) $v);
} else if ($v === null)
$sql .= 'NULL';
else
$sql .= $v;
$i += 1;
}
if (isset($sqlarr[$i])) {
$sql .= $sqlarr[$i];
if ($i+1 != sizeof($sqlarr)) ADOConnection::outp( "Input Array does not match ?: ".htmlspecialchars($sql));
} else if ($i != sizeof($sqlarr))
ADOConnection::outp( "Input array does not match ?: ".htmlspecialchars($sql));
$ret =& $this->_Execute($sql);
if (!$ret) return $ret;
}
} else {
if ($array_2d) {
if (is_string($sql))
$stmt = $this->Prepare($sql);
else
$stmt = $sql;
foreach($inputarr as $arr) {
$ret =& $this->_Execute($stmt,$arr);
if (!$ret) return $ret;
}
} else {
$ret =& $this->_Execute($sql,$inputarr);
}
}
} else {
$ret =& $this->_Execute($sql,false);
} return $ret;
}
function &_Execute($sql,$inputarr=false)
{
if ($this->debug) {
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
$this->_queryID = _adodb_debug_execute($this, $sql,$inputarr);
} else {
$this->_queryID = @$this->_query($sql,$inputarr);
}
/************************
// OK, query executed
*************************/ if ($this->_queryID === false) { // error handling if query fails
if ($this->debug == 99) adodb_backtrace(true,5);
$fn = $this->raiseErrorFn;
if ($fn) {
$fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr,$this);
}
$false = false;
return $false;
}
if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead
$rs = new ADORecordSet_empty();
return $rs;
}
// return real recordset from select statement
$rsclass = $this->rsPrefix.$this->databaseType;
$rs = new $rsclass($this->_queryID,$this->fetchMode);
$rs->connection = &$this; // Pablo suggestion
$rs->Init();
if (is_array($sql)) $rs->sql = $sql[0];
else $rs->sql = $sql;
if ($rs->_numOfRows <= 0) {
global $ADODB_COUNTRECS;
if ($ADODB_COUNTRECS) {
if (!$rs->EOF) {
$rs = &$this->_rs2rs($rs,-1,-1,!is_array($sql));
$rs->_queryID = $this->_queryID;
} else
$rs->_numOfRows = 0;
}
}
return $rs;
}
162: $sql = "SELECT `user_id` FROM `user` WHERE user_name='".$user_name."' ORDER BY `user_id` DESC";
****你先在后面加一个
echo $sql;
我看是sql语句有问题
total = $rs->RowCount();这行里$rs吧是对象。或者为NULL
在本机测试是好的 。。传到服务器上就不行了
Fatal error: Call to a member function query() on a non-object in ....
至今没找到解决的办法
如果网页用的是gbk,就$conn->exec("set character set gbk");
然后可以执行对象操作了
楼主应该用他的查询语句,你写的SQL语句不太规范。