Yii Query Builder Result (Plain Sql With Join And Subquery)

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?

Your problem is here:

The queryRow() method returns an array, which you should be accessing. You should probably be careful to check that a row has been returned before trying access the content though.




$result = $checkbook->queryRow();


// $result['booking'] etc