mysql 5.1 signal an error to cause PDO exceptions

I know mysql 5.5 allows using SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Error: ...'; to raise a user defined error. And this error will stop an INSERT operation if it was put in the BEFORE INSERT TRIGGER on some tables. And it's also convenient for PDO to catch the PDOException and output the errorinfo() i.e. MESSAGE_TEXT defined in SIGNAL SQLSTATE. However, the version of mysql on the server I rent is mysql 5.1. And I want to know how can I raise a user defined error with the features like the SIGNAL SQLSTATEMENT in mysql 5.5.

  1. interrupt a insert operation when it's in before insert trigger
  2. can be caught by PDO

I've found some topics on similar problems, and I've tried these:

  • call a nonexist procedure

    call `sp_raise_error`;

  • use a function to throw an error

https://blogs.oracle.com/svetasmirnova/entry/how_to_raise_error_in

Both can't be caught by PDO. So what's a solution? ( I tested on MySQL5.5 )

Answers


Simulate “SIGNAL SQLSTATE” Statement in Low Version MySQL to Throw Meaningful Exception | MySQL Hack


Need Your Help

Keeping track of linked lists?

c++ linked-list nodes

I'm still having trouble figuring out how to keep track of my linked lists but have come up with some progress.

Previous Page URL JSF

java jsf

I'm working with a JSF application and I'm seeing the URL that appears in the browser's navigation bar is always for the page I just left, rather than the page I'm on.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.