您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 百色分类信息网,免费分类信息发布

PHP MVC初学者问题...

2024/3/6 11:50:45发布28次查看
function postedit(){ $this->load->helper(url); $this->load->helper(form); //$sql = select * from userinfo where username = 'zhangning'; $data[user] = $this->db->query(select * from userinfo where username = '.$this->uri->segment(3).'); $this->load->view(postedit,$data); }
前台:
age ?>
a php error was encountered
severity: notice
message: undefined property: ci_db_mysql_result::$age
filename: views/postedit.php
line number: 9
啥原因呀?找了半天了。。。刚学2 3天。。看不出来哪有错。
$data[user] =fsdfsd;如果这样前台会输出值得
回复讨论(解决方案) 这个错可以不理会,定义一下错误级别就行了。
你的query只是查询,并未返回结果啊,你看看ci手册
这个错可以不理会,定义一下错误级别就行了。
你的query只是查询,并未返回结果啊,你看看ci手册
你说的该不会是这个吧
在system文件下下的database文件夹下
/** * execute the query * * accepts an sql string as input and returns a result object upon * successful execution of a read type query. returns boolean true * upon successful execution of a write type query. returns boolean * false upon failure, and if the $db_debug variable is set to true * will raise an error. * * @access public * @param string an sql query string * @param array an array of binding data * @return mixed */ function query($sql, $binds = false, $return_object = true) { if ($sql == '') { if ($this->db_debug) { log_message('error', 'invalid query: '.$sql); return $this->display_error('db_invalid_query'); } return false; } // verify table prefix and replace if necessary if ( ($this->dbprefix != '' and $this->swap_pre != '') and ($this->dbprefix != $this->swap_pre) ) { $sql = preg_replace(/(\w).$this->swap_pre.(\s+?)/, \\1.$this->dbprefix.\\2, $sql); } // compile binds if needed if ($binds !== false) { $sql = $this->compile_binds($sql, $binds); } // is query caching enabled? if the query is a read type // we will load the caching class and return the previously // cached query if it exists if ($this->cache_on == true and stristr($sql, 'select')) { if ($this->_cache_init()) { $this->load_rdriver(); if (false !== ($cache = $this->cache->read($sql))) { return $cache; } } } // save the query for debugging if ($this->save_queries == true) { $this->queries[] = $sql; } // start the query timer $time_start = list($sm, $ss) = explode(' ', microtime()); // run the query if (false === ($this->result_id = $this->simple_query($sql))) { if ($this->save_queries == true) { $this->query_times[] = 0; } // this will trigger a rollback if transactions are being used $this->_trans_status = false; if ($this->db_debug) { // grab the error number and message now, as we might run some // additional queries before displaying the error $error_no = $this->_error_number(); $error_msg = $this->_error_message(); // we call this function in order to roll-back queries // if transactions are enabled. if we don't call this here // the error message will trigger an exit, causing the // transactions to remain in limbo. $this->trans_complete(); // log and display errors log_message('error', 'query error: '.$error_msg); return $this->display_error( array( 'error number: '.$error_no, $error_msg, $sql ) ); } return false; } // stop and aggregate the query time results $time_end = list($em, $es) = explode(' ', microtime()); $this->benchmark += ($em + $es) - ($sm + $ss); if ($this->save_queries == true) { $this->query_times[] = ($em + $es) - ($sm + $ss); } // increment the query counter $this->query_count++; // was the query a write type? // if so we'll simply return true if ($this->is_write_type($sql) === true) { // if caching is enabled we'll auto-cleanup any // existing files related to this particular uri if ($this->cache_on == true and $this->cache_autodel == true and $this->_cache_init()) { $this->cache->delete(); } return true; } // return true if we don't need to create a result object // currently only the oracle driver uses this when stored // procedures are used if ($return_object !== true) { return true; } // load and instantiate the result driver $driver = $this->load_rdriver(); $res = new $driver(); $res->conn_id = $this->conn_id; $res->result_id = $this->result_id; if ($this->dbdriver == 'oci8') { $res->stmt_id = $this->stmt_id; $res->curs_id = null; $res->limit_used = $this->limit_used; $this->stmt_id = false; } // oci8 vars must be set before calling this $res->num_rows = $res->num_rows(); // is query caching enabled? if so, we'll serialize the // result object and save it to a cache file. if ($this->cache_on == true and $this->_cache_init()) { // we'll create a new instance of the result object // only without the platform specific driver since // we can't use it with cached data (the query result // resource id won't be any good once we've cached the // result object, so we'll have to compile the data // and save it) $cr = new ci_db_result(); $cr->num_rows = $res->num_rows(); $cr->result_object = $res->result_object(); $cr->result_array = $res->result_array(); // reset these since cached objects can not utilize resource ids. $cr->conn_id = null; $cr->result_id = null; $this->cache->write($sql, $cr); } return $res; }
db类是放在那个地方,你只要看手册教程乍样读就行了。
$user->age 改作 $user->age
php 的变量名、对象的属性名、数组的关联键是区分大小写的
你的 $user->age 是查询结果($data[user] = $this->db->query(select * from use ....)
如果能写成这样的话,那么对应的字段名一定也要是 age,但一般都不这么写,只是习惯性的一律小写
好啦。我知道啥原因啦。
还是自己不熟悉php原因
这些东西应该多看ci 多练就行
灰常感谢2位!!
百色分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录