BlackCatDevelopment / BlackCatCMS

BlackCat CMS is a PHP5, HTML5 content management system
https://blackcat-cms.org
Other
11 stars 9 forks source link

v1.1: Replace DB statements #249

Closed webbird closed 10 years ago

webbird commented 10 years ago

This issue collects commits concerning the switch to the Doctrine DBAL. We should prefer to use prepared statements whenever possible.

webbird commented 10 years ago

Simple way to use prepared statement with little effort (example taken from CAT_Helper_Addons):

$addon = $self->db()->query(
            'SELECT * FROM `:prefix:addons` WHERE addon_id=:id',
            array('id'=>$id)
        );

Please note that there is no need to use something like 'SELECT * FROM '.CAT_TABLE_PREFIX.'tablename ...' or sprintf( 'SELECT * FROM %stablename ...',CAT_TABLE_PREFIX) anymore. The :prefix: placeholder will be replaced by the class.database.php.

webbird commented 10 years ago

I've renamed some methods. Old methods are still available with $database global.

is_error -> isError get_error -> getError set_error -> setError (private)

New:

qb() -> returns Query Builder object conn() -> returns connection object resetError() -> cleans up error stack prefix() -> returns CAT_TABLE_PREFIX prepare() -> wrapper for PDO prepare(), replaces :prefix: in query string