1

I have this syntax on My Controller

$checkbook = Yii::app()->db->createCommand("SELECT count(b.bookingid) as booking FROM (SELECT :fname AS firstname, :mname AS middlename, :lname AS lastname, :dob AS dob) n 
                                                    LEFT JOIN passenger p ON (p.firstname=n.firstname AND p.middlename=n.middlename AND p.lastname=n.lastname AND p.dob=n.dob)
                                                    LEFT JOIN pax USING (passengerid)
                                                    LEFT JOIN booking b USING (bookingid)
                                                    LEFT JOIN journey USING (bookingid)
                                                    LEFT JOIN flight f USING (flightid)
                                                    WHERE f.origin = :origin AND f.destination = :destination AND f.departure BETWEEN :datestart AND :dateend");
        $checkbook->bindValue(":fname", $fname);
        $checkbook->bindValue(":mname", $mname);
        $checkbook->bindValue(":lname", $lname);
        $checkbook->bindValue(":dob", $dob);
        $checkbook->bindValue(":origin", $origin);
        $checkbook->bindValue(":destination", $destination);
        $checkbook->bindValue(":datestart", $datestart);
        $checkbook->bindValue(":dateend", $dateend);
        $checkbook->queryRow();

        //If Count Result 1, then Status True. If Count Result more than 1,then false. 
        if ($checkbook['booking'] == 1) {
            $status = true;
        } else {
            $this->actionDoubleBook();
            $status = false;
            return $status;
        }

But I got this Error.

Fatal error: Cannot use object of type CDbCommand as array in /home/apihost/public_html/goflight/protected/controllers/BookingController.php on line 653

Any idea? And How to make A Good Query Builder with SQL Syntax like that.

1
  • $checkbook variable contains CDbCommand object. And you try to access query results using this variable. Commented Jul 16, 2014 at 8:44

1 Answer 1

1

You have to use the result.. queryRow() will not change the query object itself but returns the result. Therefore use this

$result = $checkbook->queryRow();

then

 if ($result['booking'] == 1) {
            $status = true;
        } else {
            $this->actionDoubleBook();
            $status = false;
            return $status;
        }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, It WOrks. How Silly Iam im just made a little mistake
happens to everyone once in a while :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.