PHP Classes

File: example/recordset_1.php

Recommend this page to a friend!
  Classes of Everton da Rosa   PTK Validation   example/recordset_1.php   Download  
File: example/recordset_1.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PTK Validation
Validate values of dates, files and directories
Author: By
Last change:
Date: 9 years ago
Size: 1,842 bytes
 

Contents

Class file image Download
<?php

/*
 * Copyright (C) 2014 Everton
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * This file is a simple example of Recordset class.
 */

try{
    require
'examples.inc.php';
   
   
$pdo = new PDO('sqlite:./example.db');
   
    echo
'Success on connect to example.db'.PHP_EOL;
   
    if(
$rs = new \Ptk\db\Recordset($pdo, 'peoples')){
        \
Ptk\utils\Debug::show($rs->read());//return all data from table
       
       
\Ptk\utils\Debug::show($rs->read('age > 10000'));//return data where age > 10000
       
       
echo $rs->create(array(
           
'name' => 'john'
           
,'age' => 10
       
));//insert data into table
       
       
echo $rs->create(array(
            array(
'name' => 'mary', 'age' => 5)
            ,array(
'name' => 'gaspar', 'age' => 100)
            ,array(
'name' => 'adolf', 'age' => 50)
        ));
//insert multiple values
       
       
echo $rs->delete('age > 100');//delete with criteria
       
       
echo $rs->delete();//delete all records
       
       
echo $rs->update(array('age' => 100), 'age = 10');
    }else{
        \
Ptk\utils\Debug::show($pdo->errorInfo());
    }
   
} catch (
Exception $ex) {
    echo
$ex->getMessage();
    exit(
$ex->getCode());
}