PHP Classes

File: example2.php

Recommend this page to a friend!
  Classes of Indrek Altpere   ORM mapping class(like Hibernate), maps database table rows to objects   example2.php   Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: usage of advanced query builder
Class: ORM mapping class(like Hibernate), maps database table rows to objects
Store and retrieve objects in MySQL table records
Author: By
Last change: added missing require call to example script
Date: 16 years ago
Size: 958 bytes
 

Contents

Class file image Download
<?php
//example of advanced query builder usage
require_once 'Mysql.php';
require_once
'ExampleObject.php';
Mysql::Init('localhost', 'username', 'password', 'database');
$ex1 = new ExampleObject(array('field1`!=' => '1', 'field2`>' => '123'));
//the array key is by default the fieldname and vaue is the value in database
//but since searching by = does not cover all cases, it is possible to add additional conditions such as ( >, >=, !=, <, <= ) by adding separator ` between the fieldname and the operator
//right now in variable $ex1 there should be an object that has field1 not equal to 1 and field2 greater than 123
//it is also possible to specify AND/OR queries like: array('AND' => array('field1' => 1, 'field2' => 3, 'OR' => array('field3' => 1, 'field4' => 1))) and it would end up in a query
// WHERE field1 = 1 AND field2 = 3 AND (field3 = 1 OR field4 = 1)
// To reverse the operation prepen AND/OR with ! to get !(smth OR smth2)
?>