Created
September 22, 2008 12:21
-
-
Save kakra/11975 to your computer and use it in GitHub Desktop.
AdoDBRecord usage example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('adodbrecord/init.php'); # v0.5 or higher required | |
# CREATE TABLE cars (id INTEGER PRIMARY KEY, | |
# brand VARCHAR(50), | |
# color VARCHAR(50), | |
# destination VARCHAR(50) | |
# ) | |
require_once("AdoDBRecord://Car_Base"); | |
class Car extends Car_Base { | |
function drive_to($destination) { | |
$this->destination = $destination; | |
$this->save(); | |
} | |
function where_are_you_going() { | |
printf("I'm heading to %s in my %s %s<br>", $this->destination, $this->color, $this->brand); | |
} | |
} | |
$car = new Car(array("destination" => "sunny south", "brand" => "BMW", "color" => "red")); | |
$car->save(); | |
$car->where_are_you_going(); | |
$car->drive_to("north pole"); | |
# PHP 5.3 needed to call magic methods statically, so | |
# work around by instanciating the class as singleton | |
$Car = Singleton::instance("Car"); | |
$car2 = $Car->find_by_brand_and_color("BMW", "red"); | |
$car2->where_are_you_going(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment