Re: [PHP4BETA] SQL abstraction

From: Date: Wed, 30 Jun 1999 13:22:08 +0000
Subject: Re: [PHP4BETA] SQL abstraction
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-1746@lists.php.net to get a copy of this message
Stig Bakken wrote: > * Portable prepare/execute implementation. This means that your query > should not have one syntax for Oracle, but another for Solid. This > would require the abstraction layer to parse the query, but I think > that's ok as long as we have defined what to look for. We could also > implement a poor man's prepare/execute for the databases that don't > have it, for people who don't like messing around with magic quotes (I > don't.) I've done this for ODBC and OCI8, it's not very hard. A couple of comments related to this. If the abstraction layer is able to parse the query, then it should be possible to automatically drop certain variables from the 'select' queries. Example: $xval = ""; $yval = "foo"; db_prepare("select result from Text where X = ? and Y = ?", $xval, $yval, ""); The second parameter specifies that if any of the variables have value "" then the part of the query they occur in should be dropped. Since $xval is "" in this case, the where clause becomes equivalent to "where Y = '$yval'". This feature allows complicated queries to degenerate into simple ones when the extra variables are not needed, without cumbersome checking of all the parameters. A common use is in HTML forms, where there may be several search fields that are optional (eg. an option checkbox, or subject and author text fields). By setting the last parameter for db_prepare() to the empty string, any unset checkboxes or empty (unfilled) text fields from the form can be implicitly dropped from the SQL query. -Andrey * Anything will fit if you push hard enough *

« previous php.version4 (#1746) next »