在PDO方法上找不到Exception类

时间:2014-01-07 17:56:34

标签: php sql class autoload

我遇到了意想不到的异常。当我像这样更新数据时:

try {
  $restaurantUpd = new Restaurant();
  $restaurantUpd->updateRestaurant(array( 'restaurant_name' => Input::get('restaurant_name'),
                                          'restaurant_location' => Input::get('restaurant_location'),
                                          'restaurant_contact_email' => Input::get('restaurant_contact_email')
                                        ), $_GET['edit']);
  //ok
} catch(Exception $e) {
  die($e->getMessage());
}

它返回此错误: Warning: require_once(classes/Exeption.php): failed to open stream: No such file or directory in C:\xampp\htdocs\admintest\core\init.php on line 32

但奇怪的是我没有Exeption.php课程?另外,第32行是指我的自动加载:

/*
* Autoload function for classes
*/
spl_autoload_register(function($class) {
    require_once 'classes/' . $class . '.php';
});

我在餐厅课程中的更新方法是这样的......

public function updateRestaurant($fields = array(), $id = null) {
    if (!$this->_db->update('rt_restaurant', $id, $fields, false)) {
        throw new Exeption('There was a problem updating');
    }
}

来自DB类的更新方法是PDO prepare,execute,fetch

任何指导?

2 个答案:

答案 0 :(得分:0)

你有拼写错误 此行中的Exeption将为Exception

throw new Exeption('There was a problem updating');

如果不起作用:

试试这个:

} catch(\Exception $e) {

throw new \Exception('There was a problem updating');

来自手册 Prefixing a name with \ will specify that the name is required from the global space even in the context of the namespace.

http://www.php.net/manual/en/language.namespaces.fallback.php

答案 1 :(得分:0)

这是班级方法中的拼写错误

public function updateRestaurant($fields = array(), $id = null) {
    if (!$this->_db->update('rt_restaurant', $id, $fields, false)) {
        throw new Exeption('There was a problem updating');
    }
}

此外...抛出异常,因为de DB方法中出现错误我选择了WHERE id = $ ID

但在MySQL中,它不是id,而是rest_id。