Re: Extending PDO

From: Date: Thu, 04 Aug 2005 10:59:27 +0000
Subject: Re: Extending PDO
References: 1 2 3  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-2716@lists.php.net to get a copy of this message
Hello! Wez Furlong wrote:
Please file a bug report with a backtrace.
Richard Thomas wrote:
Was trying to make a quick wrapper for PDO as an example and am having some issues with it seg faulting
I'm also looking at PDO as basis for a leightweight DB abstraction layer, which adds some small features to make it possible to write portable applications when writing simple/standard SQL. I ran into two issues, which make writing such a layer needlessly complicated. The first issue is missing support for something like a defaultFetchMode in PDO. If you don't want to use the default fetchMode hardcoded in PDO, you have to set the fetchMode for each PDOStatement::fetch call or for each PSOstatement object. But you often have a lot of PDO::fetch calls and statements in one script, so it would be very convenient to set a defaultFetchMode when creating the DB handle, to avoid setting the fetchMode everywhere in your scripts. If you want to avoid it today, you have to extend the PDOStatement class (which leads to my second problem below) and wrap PDO::prepare calls. It also does not have any effect on PDO::query, so you have to wrap this too. There is a feature request for this issue in the bug-tracker: http://pecl.php.net/bugs/bug.php?id=4732 The second issue is PDO_ATTR_STATEMENT_CLASS, which only could be changed in PDO::prepare calls - again everywhere in your scripts. If you need to change/add somthing in the statement class, you cannot do this using a central call of PDO::setAttribute (or something like that), you have to wrap PDO::prepare and PDO::query. There is also a feature request for this issue in the bug-tracker: http://pecl.php.net/bugs/bug.php?id=4987 I have looked at the C source-code, but I'm not a C-programmer so I can't really say what had to be changed to implement these changes. However, it does not look very difficult to me, I think the code for changing PDO_ATTR_STATEMENT_CLASS could be moved and adapted from prepare to setAttribute, and prepare AND query could use the class set here. defaultFetchMode could be set by an own PHP-Methode, or setAttribute, and when a stmt-object is created (prepare, query), the stmt->default_fetch_type could be read from a variable instead of beeing hardcoded in those functions. But to say it again, I'm not a C-programmer, so it's maybe more difficult as I estimate now ;-) What do you think about the chances to get those changes into PDO (soon)? Aside from these two issues, PDO works perfectly for me! Best regards Andreas PS: I have postet my thoughts for a simple PDO based DB abstraction on pear-dev in more detail: http://news.php.net/php.pear.dev/39173

« previous php.pecl.dev (#2716) next »