Source for file example.php
Documentation is available at example.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Wolfram Kriesing, Paolo Panto, vision:produktion <wk@visionp.de>
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
// $Id: example.php 126432 2003-05-10 00:10:00Z quipo $
require_once 'MDB/QueryTool.php';
// change this!!!!! and the DSN to your DB
define ('TABLE_TIME', 'time');
if ($DB_BACKEND == 'mysql') {
$dbDSN = 'mysql://root@localhost/test';
define ('TABLE_USER', 'user');
// postgreSQL setup, use PEAR::DB >1.4b1
if ($DB_BACKEND == 'pgsql') {
$dbDSN = "pgsql://test:test@/test";
define ('TABLE_USER', 'uuser'); // user is a reserved word in postgres
// this is default, but to demonstrate it here ...
* this table spec assigns a short name to a table name
* this short name is needed in case the table name changes
* i.e. when u put the appl on a providers db, where you have to prefix
* each table, and you dont need to change the entire appl to where you refer
* to joined table columns, for that joined results the short name is used
* instead of the table name
array ('name' => TABLE_USER , 'shortName' => 'user')
,array ('name' => TABLE_TIME , 'shortName' => 'time')
// this set an error-callback method, which will be called in case something really went wrong
// you can use 'setErrorLogCallback' to define the callback method for log-messages - non critical.
// and you can use 'setErrorSetCallback' to define a callback for errors which prevent the query
// from properly executing
$user = new user($dbDSN, array ('errorCallback'=> 'myPrint'));
//$user->setErrorCallback('myPrint'); this could be used too
// get a single entry with a given 'id'
$user->reset(); // reset the query-builder, so no where, order, etc. are set
// query: SELECT * FROM user WHERE id=3
// get all entries from the table
$user->reset(); // reset the query-builder, so no where, order, etc. are set
// query: SELECT * FROM user
// get the first 10 entries from the table (LIMIT 0,10)
$user->reset(); // reset the query-builder, so no where, order, etc. are set
// query: SELECT * FROM user LIMIT 0,10
// get all data where the id>3
$user->reset(); // reset the query-builder, so no where, order, etc. are set
// query: SELECT * FROM user WHERE id>3
// setting multiple query-parts
headline('using set[Where,Order,Group]');
$user->reset(); // reset the query-builder, so no where, order, etc. are set
// for proper SQL92 i think we need to select only the col we use in group
// in mysql you can also leave out the following line
// query: SELECT * FROM user WHERE name IS NOT NULL GROUP BY name ORDER BY name
// setting multiple query-parts
$user->reset(); // reset the query-builder, so no where, order, etc. are set
// query: SELECT * FROM user
// the result-array is indexed by 'name'
// setting multiple query-parts
headline('using setIndex using 2 columns!');
$user->reset(); // reset the query-builder, so no where, order, etc. are set
// query: SELECT * FROM user
// the result-array is indexed by 'name,surname'
// join the table 'time' this automatically detects where there are
// columns that refer to one another, this uses a regExp that you can simply
// modify (see $_tableNamePreg and $_columnNamePreg), by default this maps
// stuff like 'user_id'=>'user.id'
$user->reset(); // reset the query-builder, so no where, order, etc. are set
// query: SELECT * FROM user,time WHERE user.id=time.user_id ORDER BY surname
// does the same as the example above
// only that you have to hardcode the join by hand, no autoJoin here
headline('using setJoin instead of autoJoin');
$user->reset(); // reset the query-builder, so no where, order, etc. are set
// query: SELECT * FROM user,time WHERE user.id=time.user_id ORDER BY surname
headline('adding data using $user->save($data)');
$data = array ('login'=> 'new','name'=> 'foo','surname'=> 'bar');
$fooBarId = $user->save($data);
// query: INSERT INTO user (id,login,name,surname) VALUES (<sequences>,"new","foo","bar")
headline('updating using $user->save($data)');
$data = array ('id'=> $fooBarId,'login'=> 'NEW','name'=> 'Mr. foo');
$res = $user->save($data);
// query: UPDATE user (id,login,name,surname) VALUES (<sequences>,"new","foo","bar")
headline('updating using $user->update($data)');
// query: UPDATE user (id,login,name,surname) VALUES (<sequences>,"new","foo","bar")
headline(" remove the entry \$user->remove($fooBarId)" );
$res = $user->remove($fooBarId);
// query: DELETE FROM "uuser" WHERE "id" = $fooBarId
print " <h1>$headlineCnt - $string</h1>";
Documentation generated on Mon, 11 Mar 2019 15:48:24 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|