We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Can't write to the db

Hi I have the following function:

public function addAction($name,$rating=null,$address,$city,$district=null ,$description=null){

   try{
       echo "processing";
       $chat= new Chat();
       $chat->setChatName($name);

       $chat->save();

       echo "till here";

       $institution= new Institution();
       $institution->setName($name);
       $institution->setChatId($chat->getChatId());
       $institution->setAddress($address);
       $institution->setCity($city);
       $institution->setRating($rating);
       $institution->setDescription($district);
       $institution->setDistrict($description);
       echo "wb here";
       $institution->save();
   }catch (ErrorException $e){
       echo $e;

   }

}

The output I have when I go thru the defined toute is only "processing" (the first 'echo") , nothing is added to the db. I figure out where the mistake can be.


6.0k
Accepted
answer

hi, try this:

<?php
if($chat->save() == false)
{
foreach($chat->getMessages() as $mes)
    {
        echo $mes;
    }

}
?>
edited Dec '16

If you are on developer machine you could remove try catch block and see php error information and line in your browser, and, assuming you have xdebug, much more. If you don't, I suggest you take some time to install it.

Otherwise you can use:

echo ($e->getCode());
echo($e->getMessage());
echo($e->getLine());

inside catch.