Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.


4.3k
Accepted
answer

hi, try this:

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

}
?>


6.3k
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.