 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Carson McDonald's Blog: PHP MySQLi and Multiple Prepared Statements
by Chris Cornutt February 15, 2010 @ 13:29:28
When Carson McDonald tried to get multiple prepared statements to work in his MySQLi code for his application, he got a "commands out of sync" error. Luckily, he's found a solution thanks to the store result.
Details about this error can be found in the mysql docs. Reading those details makes it clear that the result sets of a prepared statement execution need to be fetched completely before executing another prepared statement on the same connection.
He gives code snippets that are "before" and "after" examples of what he had to change to get things working. Each time its executed, the "store_result" call is made and the result set is pulled out of the prepared statement.
voice your opinion now!
prepared statement tutorial storeresult mysqli
Greebo.net: Converting your PHP app to MySQLi prepared statements
by Chris Cornutt January 04, 2010 @ 13:46:13
From Greebo.net there's a recent post that looks at converting the current database functionality in your application over to the MySQLi functionality and making use of prepared statements as a later of protection for your queries.
Okay, you've got like a zillion SQL queries in your PHP app, and probably 95% of them have a WHERE clause, and you need to make them safe so people will still download and use your app. Because if you don't fix your injection issues, I will rain fire on your ass. These are the steps you need to take to convert to prepared statements.
The guide is two steps you'll need to make the transition - "PHP 4 is dead. Upgrade to PHP 5" and "make sure your hoster has MySQLi". The major part of the update is under the first point where he gives code examples and suggestions to follow about how to "harden" your environment to prevent and issues that lax SQL methods might have caused and a simple example of a move from MySQL to MySQLi.
voice your opinion now!
mysql mysqli convert prepared statements tutorial
Rubayeet Islam's Blog: MySQL Prepared Statements and PHP A small experiment
by Chris Cornutt October 30, 2008 @ 11:13:58
In a recent post to his blog Rubayeet Islam compared the more traditional way of running a query in MySQL versus a prepared statement with the MySQLi extension.
Consider a PHP-MySQL application where the information of 1000 users is being retrieved from the database by running a for loop [...] in each iteration, the first thing the MySQL engine does is to parse the query for syntax check. Then it sets up the query and runs it. Since the query remains unchanged during each iteration(except for the value of user_id), parsing the the query each time is definitely an overhead. In such cases use of prepared statements is most convenient.
He explains what prepared statements are and some of the advantages around them and includes some benchmarking examples to show the differences - about a five second jump in favor of MySQLi.
voice your opinion now!
mysqli prepared statement tutorial benchmark
DevShed: Working with Prepared Queries with PDO Objects in PHP 5
by Chris Cornutt June 11, 2007 @ 13:21:00
DevShed concludes their series looking at the use of PDO objects in PHP5 with this last tutorial focusing on the use of prepared queries in your PHP application.
In this last tutorial in the series I'm going to show you how to run prepared queries, but in this case we're going to include named parameters into them. Additionally, I'm going to take a quick look at some additional methods bundled with this extension. These new methods can be really useful for working with transactions, in case you want to use this feature with the database system of your choice.
They start with a simple approach to using prepared queries before moving on to an alternate method - binding parameters to the query via bindParam. They wrap up the article with a look at using transactions, both commits and rollbacks.
voice your opinion now!
prepared query php5 tutorial pdo object prepared query php5 tutorial pdo object
Jeff Moore's Blog: PDO versus MDB2
by Chris Cornutt December 27, 2006 @ 10:41:00
In the constant pursuit of exploring what else is out there, Jeff Moore took a look at using PDO and MDB2 in some of his scripts and tried it out in a simple test program:
I was just putting together a small test program and I thought I would try using PDO. I really haven't done anything serious with PDO, just try it a couple times. Unfortunately, this didn't work and it took me a few minutes to figure out why. Actually, I still don't know exactly why it doesn't work, but I did find a way to make it work.
He found PDO slightly different to work with than what he was used to so he moved on to MDB2 to see how the same code would fare there. Things worked smoothly there, handling the prepared statements he wanted to use perfectly.
voice your opinion now!
pdo mdb2 database test prepared statement pdo mdb2 database test prepared statement
Brian Moon's Blog: PDO Turbo Button
by Chris Cornutt August 25, 2006 @ 08:09:32
On the "Ramblings of a web guy" blog by Brian Moon, there's a good look at some benchmarks run with PDO, normally versus with the "turbo button" as talked about by Wez.
So, a while back, I did some tests with the mysql, mysqli and PDO extensions. In those tests, I found PDO to be much slower for selects than mysql and mysqli. Half as slow in fact.
So, I decided to try Wez's trick of emulating prepared statements to see how PDO did. The results were interesting. Not sure if these are the "fair comparisons" that Wez wants to see, but I gave it my best shot.
His first set of stats was pretty close to his originals back when he first tested, and the second set of tests (with the "button" on) seem to be a bit hit and miss on the performance upgrade using this method.
I ran this several times. Maybe Wez or someone that works on PDO can shed some light on this. Seems like it would be tough to keep track of when to use this flag and when not to.
voice your opinion now!
pdo turbo button speed benchmark test prepared statement pdo turbo button speed benchmark test prepared statement
Wez Furlong's Blog: Using PDO MySQL?
by Chris Cornutt April 24, 2006 @ 07:03:01
In this new post from Wez Furlong, he looks ar some of the things that the native MySQL client library does (the silly things) and recommends an alternative with the PDO libraries.
I've recently discovered a few things about how the mysql client library does things that seem a bit silly to me, so I'm going to share them with you.
Among the things he mentions functionality (dealing with prepared statements) like "native prepared statements cannot take advantage of the query cache" and "native prepared statements cannot execute certain types of queries". The gives a simple line of code to make the database functionality (in PHP 5.1.3 and later) use the native PDO query parser to be loaded versus the one for the standard MySQL client libraries.
voice your opinion now!
mysql pdo prepared statements client library mysql pdo prepared statements client library
|
Community Events
Don't see your event here? Let us know!
|