User tests: Successful: Unsuccessful:
Pull Request porting joomla-framework/database@66035e4.
This implements prepared statement support for the PDO MySQL driver. The base PDO driver class inherently supports prepared statements for all PDO based objects but the query builder class must implement the required interface for this to work.
Additionally, the unit test class for the query object is backported from the Framework.
The prepared statement API really isn't documented because none of the drivers that the CMS application supports use this feature, until now. With that said, the best demonstration of how to use it for PDO can be found in the added unit test case for the driver itself. Testing existing code on a PDO MySQL environment by replacing values with bound parameters as demonstrated in the test case should suffice for this. As an example, you could update JComponentHelper::load()
to use this code snippet:
// The bind method uses references for the second argument, so we need to make this a variable
$type = 'component';
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('extension_id AS id, element AS "option", params, enabled')
->from('#__extensions')
->where($db->quoteName('type') . ' = :component')
->bind('component', $type);
$db->setQuery($query);
N/A; the prepared statement API is only documented via the automatically generated API documentation
Category | ⇒ | Libraries Unit Tests |
Status | New | ⇒ | Pending |
Labels |
Added:
?
?
|
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-09-12 20:53:54 |
Closed_By | ⇒ | mbabker |
Closing due to lack of interest and an inability to use prepared statements on all supported databases (the legacy MySQL driver does not support prepared statements in any way).