Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*#############################
- * Developer: Mohammad Sharaf Ali
- * Designation: Web Developer
- * Version: 1.0
- */#############################
- // LIBRARIES
- require_once 'db/NotORM.php';
- // CONSTANTS
- const DB_HOST = 'your-host';
- const DB_USER = 'your-user';
- const DB_PASS = 'your-pass';
- const DB_NAME = 'your-dbname';
- const DB_TABLE = 'your-table';
- const DB_DSN = 'mysql:dbname='. DB_NAME. ';host='. DB_HOST;
- // DB STRUCTURE
- $structure = new NotORM_Structure_Convention(
- $primary = 'ID',
- $foreign = '%s_ID',
- $table = '%s',
- $prefix = '');
- $pdo = null;
- $db = null;
- // HELPER METHODS
- function dbConnect() {
- global $pdo;
- global $db;
- global $structure;
- $pdo = new PDO(DB_DSN, DB_USER, DB_PASS); // array(PDO::ATTR_PERSISTENT => true) // make persistent connection
- $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $db = new NotORM($pdo, $structure); // new NotORM_Cache_Session()); // enable NotORM caching
- }
- function dbClose() {
- global $pdo;
- global $db;
- $pdo = null;
- $db = null;
- }
- function toScreen($data, $exit = 0, $escape = 0) {
- echo '<pre>';
- if (is_array($data)) {
- print_r($data);
- } else {
- if ($escape) {
- echo nl2br($data);
- } else {
- echo $data;
- }
- }
- echo '</pre>';
- ob_flush();
- flush();
- if ($exit) {
- exit;
- }
- }
- // MAIN
- dbConnect();
- $data = array(
- 'fld1' => 'val1',
- 'fld2' => 'val2',
- 'fld3' => 'val3',
- 'fld4' => 'val4'
- );
- $resultInsert = $db->yourtablename()->insert($data); // you cannot get insert sql
- toScreen(iterator_to_array($resultInsert)); // notorm object to assoc array
- $resultSelect = $db->yourtablename(); // you can get select sql e.g. echo $db->yourtablename();
- toScreen(array_map('iterator_to_array', iterator_to_array($resultSelect))); // notorm object to assoc array, you can also use foreach loop
- dbClose();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement