<?php
/* Example Script UPDATE operation
*
* Copyright 2012 Soluções Office (www.solucoesoffice.com.br)
*
* 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, version 3 of the License.
*
* 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/>.
*/
/* Example table name: user
* Fields:
* id INT Primary Key, must be present, although it doesn't need to be the first field
* date_created DATETIME optional. If present, is automatically filled with the date and time of the INSERT operation.
* date_updated DATETIME optional. If present, is automatically filled with the date and time of the INSERT/UPDATE operation.
* name VARCHAR(100)
* surname VARCHAR(100)
* username VARCHAR(50)
* password VARCHAR(50)
*/
/* Folder structure:
* /project/Configs
* core.ini
* /project/library
* Configs.php
* DConnect.php
* Model.php
* /project/update.php
*/
//Requires of the dependencies
require 'library/Configs.php';
require 'library/DConnect.php';
require 'library/Model.php';
//Defines the path to the Configs INI folder.
define(CONFIGS, 'Configs');
define('DS', DIRECTORY_SEPARATOR);
//The class USER extends Model, and has the same name as the table to which it refers
class User extends Model {}
//UPDATE: 1 is the ID of the user to be updated
$user = new User(1);
$user->name = 'Another User';
//UPDATES the object. Returns TRUE, or PDOException object if error.
$ok = $user->save();
//to retrieve id, one can use $id, or $user->id
echo $user->id . ' ' . $user->name . ' ' . $user->surname . ' ' . $user->username . ' ' . $user->password . '<br />';
echo $user->date_created . ' ' . $user->date_updated;
/* RESULTS
* 1 Another User Surname Username Password
* 2012-11-19 14:27 2012-11-19 15:03
*/
|