Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catchable fatal error: Object of class stdClass could not be converted to string in..when tried to insert into database

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);

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.

like image 271
AssamGuy Avatar asked Feb 01 '12 10:02

AssamGuy


2 Answers

$this->get_invoice_number() is probably returning an object.

you can cast it to a string:

$invoice_number = (string) $this->get_invoice_number();
like image 109
konsolenfreddy Avatar answered Sep 30 '22 07:09

konsolenfreddy


There is nothing wrong in line 1038,
most likely is line 1037 having an error
(valuable casting issue)

$invoice_number = $this->get_invoice_number();

You should do a

var_dump( $this->get_invoice_number() );

Then likely you just need to refer to the object property like

$invoice_number->SOME_PROPERTY;
like image 20
ajreal Avatar answered Sep 30 '22 06:09

ajreal