大佬教程收集整理的这篇文章主要介绍了php-CodeIgniter-类CI_DB_mysqli_result的对象无法转换为字符串,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在使用COdeIgniter.我正在尝试根据电子邮件地址更新数据库中的密码.否则,我会遇到问题,请使用以下代码更新在CodeIgniter网站上找到的数据库.
$this->db->set('field', 'field+1', falSE);
$this->db->where('id', 2);
$this->db->update('myTable'); // gives updatE myTable SET field = field+1 WHERE id = 2
我收到的错误消息是
@H_404_12@
Object of class CI_DB_MysqLi_result Could not be converted to String
我在互联网上发现了很多谈论这种问题的话题.但是,我没有找到适合我的情况的任何内容.如前所述,我已经尝试过像这样返回查询结果
if ($query->num_rows() == 1)
{
return $query->result();
}
else
return falSE;
正如您所猜测的,这没有改变任何东西.所以希望有人能够向我解释发生了什么.这是我的模型代码.我没有写完整的代码,因为我觉得它足够满足我的需求,但是问我是否还需要其余的代码.
<?PHP if (!defined('BASEPATH')) exit('No direct script access allowed');
class Reset_password extends CI_Model
{
function __construct()
{
parent:: __construct();
$this->load->Helper('url');
$this->load->Helper('String');
}
function index($email) //function wchich will reset the password in the database;
{
$new_password = random_String('alnum', 16);
//generate random password, already try to remove and put for exemple
//$new_password = 'lol'; and doesn't work so I suppose this line isn't
//the pb
$this-> db->set('password', md5($new_password), falSE);
$this-> db->where('email', $email);
$this-> db->update('CI_TEST');
$query = $this->db->get();
}
}
谢谢 :)
编辑:这是我的控制器代码
<?PHP if (!defined('BASEPATH')) exit('No direct script acess allowed');
class Forget_password extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->Helper(array('form'));
$this->load->model('Reset_password');
$this->load->library('email');
}
function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callBACk_email_check', 'Error: please provide a valide email adresse');
if ($this->form_validation->run() == falSE)
{
$this->load->view('Forget_password');
}
else
{
//loading
}
}
function email_check($email)
{
$this-> db->SELEct('email');
$this-> db->from('CI_TEST');
$this-> db->where('email', $email);
$this-> db->limit(1);
$query = $this-> db->get();
if ($query->num_rows() == 1)
{
$this->Reset_password->index($query);
return (true);
}
else
{
echo 'Error: The email you provided doesn\'t exist in the database';
return (false);
}
}
}
?>
解决方法:
当前,您已经获取了一个结果集,然后需要使用result()或row()将结果收集到格式化的对象中(如果选择result_array(),则为数组). CI_DB_MysqLi_result是一个类包装程序,用于包装结果,但尚未提取其中包含的数据.
$this->db->SELEct('email');
$this->db->from('CI_TEST');
$this->db->where('email', $email);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1)
{
//Use row() to get a single result
$row = $query->row();
//$row will Now have if you printed the contents:
//print_r( $row );
//stdClass Object ( [email] => example@gmail.com )
//Pass $query->email directly to reset_password
$this->Reset_password->index( $row->email );
return true;
}
以上是大佬教程为你收集整理的php-CodeIgniter-类CI_DB_mysqli_result的对象无法转换为字符串全部内容,希望文章能够帮你解决php-CodeIgniter-类CI_DB_mysqli_result的对象无法转换为字符串所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。