Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I prevent long queries in PDO?

Is there any way to make a PDO object throw an error if a query takes too long? I have tried PDO::ATTR_TIMEOUT to no effect.

I'd like a way to have a query throw an error if it is running for longer than a certain amount of time. This is not something that I can do in the database, ie, no maintenance jobs running on the db or anything.

like image 533
Brian Ramsay Avatar asked Aug 21 '09 18:08

Brian Ramsay


People also ask

Does PDO prepare prevent SQL injection?

Also, calling PDO::prepare() and PDOStatement::execute() helps to prevent SQL injection attacks by eliminating the need to manually quote and escape the parameters.

How to SELECT data in PDO?

To select data from a table using PDO, you can use: The query() method of a PDO object. Or a prepared statement.

How PDO works?

PDO—PHP Data Objects—are a database access layer providing a uniform method of access to multiple databases. It doesn't account for database-specific syntax, but can allow for the process of switching databases and platforms to be fairly painless, simply by switching the connection string in many instances.


2 Answers

I'm not sure what you mean by "This is not something that I can do in the database", but I would suggest that you have the person administering the database set up an Oracle profile to limit this on the database side. There are parameters such as CPU_PER_CALL and LOGICAL_READS_PER_CALL that can cap queries. The profile can be applied only to specific users if desired.

like image 154
dpbradley Avatar answered Oct 05 '22 07:10

dpbradley


I'm not sure if you can do this in Oracle but I'm going to say it's not possible to do this within PHP since PHP is issuing the query to Oracle to be run and then is waiting for Oracle's response back. It may be possible to modify the PDO extension to support this, but you would need to modify the extension code (the actual C code) as there probably isn't any way to do this in just PHP.

like image 21
Steven Surowiec Avatar answered Oct 05 '22 07:10

Steven Surowiec