473,670 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PDOException : get the bad query with exception handler

Hello,

I got and an exception handler, and I want, for each PDOException
throwned, to get the whole query which didn't works.
Is there a way to do this ?

Thanks,

Tonio

Feb 19 '07 #1
6 8122
Tonio wrote:
I got and an exception handler, and I want, for each PDOException
throwned, to get the whole query which didn't works.
Not from the exception itself, no.

$exception->errorInfo[2] has some useful info, but its contents are
engine-specific, so may or may not contain the original SQL query
that triggered the error.

Why do you want to know the offending SQL query anyway? If you report
it back to the user, it could reveal a vulnerability in your code,
which could be used by a malicious user as a weak point to break into.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Feb 19 '07 #2
On 19 Feb, 12:58, Toby A Inkster <usenet200...@t obyinkster.co.u k>
wrote:
Why do you want to know the offending SQL query anyway? If you report
it back to the user, it could reveal a vulnerability in your code,
which could be used by a malicious user as a weak point to break into.
Maybe he wants to log it somewhere.

Feb 19 '07 #3
Maybe he wants to log it somewhere.
That's it ! :)

Feb 20 '07 #4
So, what I do :

I extend Pdo and keep the last query in a static variable, kept up-to-
date by extending the query,and prepare method. (At minimum ;))
That is logged by the exceptionHandle r when an error occurs.

Sorry for this horrible english ;)

Tonio

Feb 20 '07 #5
Tonio wrote:
>Maybe he wants to log it somewhere.

That's it !
My only advice then would be to try extending PDO itself:

class MyPDO extends PDO
{
function query ($q)
{
try
{
return parent::query($ q);
}
catch (PDOException $e)
{
$e->errorInfo[999] = $q;
throw $e;
}
}
function exec ($q)
{
try
{
return parent::exec($q );
}
catch (PDOException $e)
{
$e->errorInfo[999] = $q;
throw $e;
}
}
}

Then instead of using PDO, use MyPDO instead. When a PDOException is
thrown, you will now be able to inspect $e->errorInfo[999] to find the
cause of the error.

If you use prepared statements (and it is generally a good idea to do so!)
then you will also want to extend PDO->prepare() and PDOStatement->execute().
The only problem I forsee with that is a possible difficulty in cajoling
MyPDO->prepare() to return a MyPDOStatement object instead of a PDOStatement
object.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Feb 20 '07 #6
Humm, good idea, nicer as mine !

Thanks a lot !

Feb 21 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2566
by: juergen perlinger | last post by:
Hello out there. sometimes I need to have proper control of the floating point arithmetic of the C(and C++) runtime system, and using the f.p. exception handling of the C99 standard is quite handy for that purpose. The only problem when dealing with f.p. exception signals is that there is (afaik) no specification *when* the f.p. exception is raised, with one notable exception: 'feraiseexcept(int)' raises the exceptions passed in the...
44
4207
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
40
13511
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
2
1297
by: | last post by:
I would appreciate some help in understanding the simple C# example relating to handling exceptions. This one relates to catching an error thrown by dividing number by zero. There are a few things I don't understand which I hope you can help me with: 'using System;
2
3871
by: Seth | last post by:
Ok, here is my setup. I have a fully functioning HTTP Handler implemented. The handler is supposed to handle every single request that comes in to a particular virtual directory. Thus, in IIS, I have a mapping of .* to the aspnet_isapi.dll. And my web.config has an entry thusly: <add verb="*" path="*" type="HandlerClass, HandlerAssembly" /> And this is working just fine thus far. The handler gets all the requests and works like a...
2
1314
by: Nak | last post by:
Hi there, I'm just curious as to something. I have just added an exception handler at the entry point to my application, within the IDE any unhandled exceptions fallback to this and enable me to disable a dialog of my liking. Now if I run the application outside of the IDE I recieve the standard "Unhandled exception" dialog provided by .NET giving me the ability to continue or quit. I wasn't actually aware that exception handling...
11
5576
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
16
5049
by: john6630 | last post by:
Coming from the .Net world, I am used to the try...catch...finally approach to error handling. And PHP 5 now supports this approach. But I am not clear what happens to unhandled errors/exceptioins? Do I define a default error handler as well as do my try/catch? Can I mix error handling with the exceptions? Is one approach better than the other? TIA John
6
4388
by: Steve | last post by:
Hi All I have a windows forms Application (SAM) in vb.net 2008 using .net framework V2 One and only one customer out of 30 customers is getting errors daily where they have to close and restart my application, sometimes several times a day The customer has XP Home SP2
0
8468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8660
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7415
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4209
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.