Skip to content
Nolan Chou edited this page May 26, 2015 · 6 revisions

Datebase

Quick

1.Create a link to datebase with project's db config (/conf/db.php).
use pt\framework\db as db;
$db = db::init();
// or
$db = \pt\framework\db::init();
2.Create a link to other config.
$newconfig = array(
    'dsn'               => 'mysql:dbname=demo;host=localhost:3306',
    'username'          => 'root',
    'password'          => 'root',
    'charset'           => 'utf8',
);
$db = db::init($newconfig);
3.Execute a sql statement.
$row = $db -> prepare("SELECT * FROM `table` WHERE `id`=:id") 
           -> execute(array(':id'=>1));

If it's a select query, will return the selected rows;
A Update/Delete query, will return effect rows number;
A Insert query, will return last_insert_id or effect rows number;

4.Execute a same query.
$row2 = $db -> execute(array(':id'=>2));

Config

  • dns : pdo's DSN to connect to the database
  • username
  • password
  • charset : default "utf8"

Information

  • License Agreement
  • Change Log

Tutorial

Advanced

  • Dynamic expansion of class
  • Callback
  • Hook

Tools

  • File
  • Image
  • Page
  • String
  • Upload
  • Action (hook)
  • Filter (hook)
Clone this wiki locally