1

I'm rather new to PHP, and I want to:

  1. define a class in the main directory of my web application and use it in sub-directories.
  2. the class receives MySQL delete statements, executes them and catches foreign key constraint exception.

This is the class so far:

class MySQLErrorHandling
    {
        public function query($query_string)
            {
                try 
                   {
                      $conn = mysql_query($query_string);

                      if (!$conn) 
                      throw new Exception("mysql Error:");
                   } 
                catch(Exception $e) 
                   {
                      echo $e->getMessage(). mysql_error();
                   }
            }
    }

Any suggestions? Appreciated.

4

1 回答 1

-1

我建议不要捕获外键约束异常,而是使用ON DELETE CASCADE. 数据库将负责正确删除项目。查看文档

于 2012-09-19T11:21:22.437 回答