 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Volker Dusch's Blog: References suck! - Let's fix MySqli prepared statements!
by Chris Cornutt June 14, 2011 @ 11:46:55
Volker Dusch has a new post to his blog looking at the use of references in PHP (or lack there of) and what we, as end users of the language, can do about it. His example looks at mysqli prepared statements.
Even so not every PHP Developers knows WHY we don't use references pretty much every core function and every somewhat modern framework avoids them so people adapted this best practice. The leftovers in the PHP core, like sort() or str_replace(), are exceptions to the rule. So if the common consensus is, or at least 'should be', that we should not use references then maybe we should start looking for places where they hurt and how we could fix them?
He talks about prepared statements and one thing he sees that makes it a "hard sell" to developers needing a good way to query their databases. He points out the difference in code required between the normal MySQL calls and mysqli (hint: it's more) and shows how to use an abstraction layer to make things a bit easier. He points out the downfalls of using this approach, mainly the performance hit you get (from using his fetchAll method).
voice your opinion now!
references mysqli prepared statement performance abstraction
Johannes Schluter's Blog: Escaping from the statement mess
by Chris Cornutt May 19, 2011 @ 09:30:45
In a new post to his blog Johannes Schluter suggests an alternative to using prepared statements in PHP applications using a database - creating a handler method that allows for dynamic queries as well as proper escaping of values.
Now prepared statements were a nice invention some 30 years ago abut they weren't meant for making things secure and so they do have some shortcomings: One issue is that preparing and executing a query adds a round-trip to the server where it then requires resources. [...] With prepared statements you first have to build the list of place holders (the exact amount of place holders (?) separated by a comma, without trailing comma) and then bind the values and mind the offsets when having other values - this typically becomes ugly code.
He includes the code for his alternative, a function using the mysqli extension to let you create dynamic SQL that still uses placeholders and proper escaping to prevent both SQL injection issues and resources problems caused by the multiple hops back to the database.
voice your opinion now!
prepared statement database alternative mysqli
NETTUTS.com: The Problem with PHP's Prepared Statements
by Chris Cornutt August 09, 2010 @ 10:09:01
On NETTUTS.com there's a new tutorial talking about the problem with PHP's prepared statements, mainly due to their flexibility.
There are a couple issues that appear to make these methods less flexible than we'd hope. For one, we must utilize the bind_result method, and pass in a specific number of variables. However, what happens when this code is within a class, and we won't immediately know how many variables to pass? Luckily, there's a solution! I'll show you what it is in today's video tutorial.
The tutorial is screencast but they've also included the full code ready for cut and pasting into your favorite editor of choice.
voice your opinion now!
tutorial screencast prepared statement
Andrey Hristov's Blog: Replacing mysqli's Connection, Result and Statement classes
by Chris Cornutt July 09, 2010 @ 10:31:03
On his blog today Andrey Hristov has a quick post that talks about two methods to extend the functionality that the mysqli extension offers in PHP with your own custom code.
Have you ever though about extending mysqli's classes. It's pretty simple to subclass the connection class mysqli. However, subclassing mysqli_result and mysqli_stmt is not so obvious, actually I though that it's even not possible. However, never say never! After discussing mysqli's OO interface for an hour yesterday [...] I found out how one can plug his own classes.
Two code examples are provided - one for extending the mysqli_result and the other extending the mysql_stmt class. You can find more about these and other classes the mysqli extension has to offer in this section of the PHP manual.
voice your opinion now!
replace mysqli connection result statement class extend
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
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
Harry Roberts' Blog: Manipulating PHP arrays with SQL
by Chris Cornutt May 22, 2008 @ 14:39:54
Harry Roberts has a quick post to his blog today showing a method he's come up with to handle PHP arrays from inside of SQL statements (a port of the JsonSQL library to PHP).
Trent Richardson created a very small and simple JsonSQL library for JavaScript which allows you to run an extremely limited subset of SQL against a Json array/object. I quickly ported it over to PHP 5 and it works like a charm, although the syntax for the WHERE clause isn't exactly the same but the rest ported across properly.
He's included some sample source code of it in action - selecting information out of an array of user information, once changing their order and the other grabbing a username. Complete source for the library is included too.
voice your opinion now!
manipulate array sql statement phpsql library port jsonsql
|
Community Events
Don't see your event here? Let us know!
|