so i created 2 database classes to use with mysql/php.
1 x mysqli oop db class
1 x pdo oop db class
the aim/point of this was to build some kind of structure to using both mysqli or pdo
in a slightly more clean/tidy way.
examples:
mysqli oop db class usage examples:
pdo oop db class usage examples:
the files/classes themselves will be stored/hosted on GitHub due to me maybe updating from time to time/
you can get the classes yourself here at:
if anyone likes or uses these. a like/thanks would be appreciated.
hope you like them.
p:s i will be getting to work shortly on a new pdo forum type script.
(ive dropped my mysqli version due to loony talking my ears off about pdo lol)
i will be hosting/storing the progress of this on GitHub also if anyone will be interested in that also.
1 x mysqli oop db class
1 x pdo oop db class
the aim/point of this was to build some kind of structure to using both mysqli or pdo
in a slightly more clean/tidy way.
examples:
mysqli oop db class usage examples:
PHP Code:
require_once('mysqli.class.php');
// multi row table
$categories = db::mysqli()->query('SELECT * FROM `categories`');
if($categories->count() > 0):
foreach($categories->result() as $category):
echo $category->title, '<br/>';
echo $category->description, '<br/>';
endforeach;
endif;
db::mysqli()->query('UPDATE `config` SET `site_name`="codemafia"');
// single row table
$query = db::mysqli()->query('SELECT * FROM `config`');
// then use our result function as an array instead:
$config = $query->result()[0];
echo $config->site_name, '<br/>';
echo $config->timezone, '<br/>';
db::mysqli()->close();
PHP Code:
require_once('pdo.class.php');
// multi row table
db::pdo()->query('SELECT * FROM `categories`');
// or with bind
//db::pdo()->query('SELECT * FROM `categories` WHERE `id` = :id');
//$placeholders = array(':id' => '1');
//db::pdo()->bind($placeholders);
db::pdo()->execute();
if(db::pdo()->count() > 0):
foreach(db::pdo()->result() as $category):
echo $category->title, '<br/>';
echo $category->description, '<br/>';
endforeach;
endif;
db::pdo()->query('UPDATE `config` SET `site_name`="codemafia"');
db::pdo()->execute();
// single row table
db::pdo()->query('SELECT * FROM `config`');
db::pdo()->execute();
// then use our result function as an array instead:
$config = db::pdo()->result()[0];
echo $config->site_name, '<br/>';
echo $config->timezone, '<br/>';
db::pdo()->close();
you can get the classes yourself here at:
if anyone likes or uses these. a like/thanks would be appreciated.
hope you like them.
p:s i will be getting to work shortly on a new pdo forum type script.
(ive dropped my mysqli version due to loony talking my ears off about pdo lol)
i will be hosting/storing the progress of this on GitHub also if anyone will be interested in that also.
Comment