可捕获的致命错误:试图插入数据库时​​,类stdClass的对象无法转换为字符串in .. [英] Catchable fatal error: Object of class stdClass could not be converted to string in..when tried to insert into database

查看:101
本文介绍了可捕获的致命错误:试图插入数据库时​​,类stdClass的对象无法转换为字符串in ..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在stackoverflow中发现了类似我的类似查询,但是没有找到解决方案.所以我再问一次.我有以下insert查询:

I have found similar queries like mine in stackoverflow,but found no solutions . So I am asking it again. I have the following insert query :

$purchase_date = date("Y-m-d");

    $init = substr($info[fname], 0, 2);
    $odr = rand(0,255);

    $invoice_number = $this->get_invoice_number();

    //$invoice_number = $invoice_number+1;
    //$invoice_number = 400 + rand(0,100);
    $order_number = $init.'-'.$odr;


    $session_id = session_id();

    $sql = "
        INSERT INTO
            tbl_checkout
        SET
            fname = '$info[fname]',
            lname = '$info[lname]',
            email = '$info[email]',
            phone = '$info[phone]',
            address = '$info[address]',
            pin = '$info[pin]',
            session_id = '$session_id',
            purchase_date = '$purchase_date',
            invoice_number = '$invoice_number',
            order_number = '$order_number'             <----This is line no 1038
    ";
    $this->db->insertQuery($sql);

但是当我尝试执行它时,它会显示类似Catchable fatal error: Object of class stdClass could not be converted to string in c:\.....on line 1038

But when I tried to execute it, it shows error like Catchable fatal error: Object of class stdClass could not be converted to string in c:\.....on line 1038

我迷路了,因为我什至无法理解错误的含义!请帮忙.

I am lost because I can't even understand what the error means ! Please help.

推荐答案

$this->get_invoice_number()可能正在返回对象.

您可以将其转换为字符串:

you can cast it to a string:

$invoice_number = (string) $this->get_invoice_number();

这篇关于可捕获的致命错误:试图插入数据库时​​,类stdClass的对象无法转换为字符串in ..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆