За последние 24 часа нас посетили 19205 программистов и 1647 роботов. Сейчас ищут 705 программистов ...

PDO Exception

Тема в разделе "Прочие вопросы по PHP", создана пользователем krok, 13 сен 2013.

  1. krok

    krok Новичок

    С нами с:
    13 сен 2013
    Сообщения:
    1
    Симпатии:
    0
    Привет! Поздравляю с Днем Программиста!

    К вопросу...

    Имеется скрипт:
    Код (Text):
    1.  
    2. abstract class abstract_database
    3. {
    4.     /**
    5.      * @var null
    6.      */
    7.     private $_pdo = null;
    8.  
    9.     /**
    10.      * @var null
    11.      */
    12.     private $_reflection = null;
    13.  
    14.     /**
    15.      * @var null
    16.      */
    17.     private $_table_prefix = null;
    18.  
    19.     /**
    20.      * @var null
    21.      */
    22.     private $_args = null;
    23.  
    24.     /**
    25.      * @param string $dsn
    26.      * @param string $user
    27.      * @param string $password
    28.      * @param array $driver_options
    29.      */
    30.     public function __construct($dsn, $user, $password, array $driver_options = array())
    31.     {
    32.         try {
    33.             $this->_pdo = new PDO($dsn, $user, $password, $driver_options);
    34.         } catch (PDOException $e) {
    35.             $this->_showError($e);
    36.         }
    37.  
    38.         try {
    39.             $this->_reflection = new ReflectionClass($this->_pdo);
    40.         } catch (ReflectionException $e) {
    41.             $this->_showError($e);
    42.         }
    43.     }
    44.  
    45.     /**
    46.      * @param string $name
    47.      * @param mixed $args
    48.      * @return mixed
    49.      */
    50.     public function __call($name, $args)
    51.     {
    52.         $this->_args = $args;
    53.  
    54.         try {
    55.  
    56.             if ($this->_reflection->hasMethod($name)) {
    57.                 $method = $this->_reflection->getMethod($name);
    58.                 if ($method->isPublic() && !$method->isAbstract()) {
    59.  
    60.                     if (in_array($name, array('exec', 'query', 'prepare'))) {
    61.                         $args = $this->_tablePrefix(array_shift($args));
    62.                     } elseif (in_array($name, array('quote', 'lastInsertId'))) {
    63.                         $args = array_shift($args);
    64.                     }
    65.  
    66.                     try {
    67.                         return $method->invoke($this->_pdo, $args);
    68.                     } catch (PDOException $e) {
    69.                         $this->_showError($e);
    70.                     }
    71.                 }
    72.             }
    73.  
    74.             throw new ReflectionException('Reflection: The method is not defined!');
    75.  
    76.         } catch (ReflectionException $e) {
    77.             $this->_showError($e);
    78.         }
    79.     }
    80.  
    81.     /**
    82.      * @param string $prefix
    83.      * @return string
    84.      */
    85.     public function tablePrefix($prefix)
    86.     {
    87.         $this->_table_prefix = $prefix;
    88.     }
    89.  
    90.     /**
    91.      * @param string $statement
    92.      * @return string
    93.      */
    94.     private function _tablePrefix($statement)
    95.     {
    96.         return str_replace('#_', $this->_table_prefix, $statement);
    97.     }
    98.  
    99.     /**
    100.      * @param Exception $e
    101.      */
    102.     private function _showError(Exception $e)
    103.     {
    104.         header('Content-type:text/plain; charset=utf-8;');
    105.         die($e->getMessage() . PHP_EOL . PHP_EOL . $e->getTraceAsString() . PHP_EOL . PHP_EOL . implode(
    106.                 PHP_EOL,
    107.                 $this->_args
    108.             ));
    109.     }
    110. }
    Затем в моделе использую

    Код (Text):
    1.  
    2.  
    3.     function update_records($fields)
    4.     {
    5.         $rs = $this->_db->prepare(
    6.             'UPDATE ' . $this->_table . ' SET `hidden` = 0'
    7.         );
    8.         $rs->execute();
    9.  
    10.         $update_rs = $this->_db->prepare(
    11.             'UPDATE ' . $this->_table . ' SET `hidden` = :hidden WHERE `id`= :id'
    12.         );
    13.  
    14.         $delete_rs = $this->_db->prepare(
    15.             'DELETE FROM ' . $this->_table . ' WHERE `id` = :id'
    16.         );
    17.  
    18.         foreach ($fields as $row_id => $row) {
    19.             if (isset($row['delete'])) {
    20.                 $delete_rs->execute(array(':id' => $row_id));
    21.             } else {
    22.                 $update_rs->execute(array(':hidden' => $row['hidden'], ':id' => $row_id));
    23.             }
    24.         }
    25.     }
    И при удалении записи вижу крит:

    http://joxi.ru/uAYzUtg5CbBEbuNtOLY

    В xdebug:

    xdebug.show_exception_trace=Off

    Подскажите, почему exception не перехватывается в abstract_database->__call

    Заранее благодарю!