PHP Classes

File: examples/example2/exercise1.php

Recommend this page to a friend!
  Classes of Jorge Castro   PDO One ORM   examples/example2/exercise1.php   Download  
File: examples/example2/exercise1.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PDO One ORM
Access SQL database tables as object using PDO
Author: By
Last change:
Date: 1 year ago
Size: 1,080 bytes
 

Contents

Class file image Download
<?php

use eftec\PdoOneORM;
use
eftec\examples\example2\repo\CityRepo;

include
__DIR__."/../../vendor/autoload.php"; // edit the path for the correct one.

$conn= PdoOneORM::factoryFromArray([
   
'databaseType' => 'mysql',
   
'server' => '127.0.0.1',
   
'user' => 'root',
   
'pwd' => 'abc.123',
   
'database' => 'sakila',
]);
// you can include the PHP file generated previously or copy and paste its configuration.
$conn->open(); // opens the database connection. $conn is a singleton, so you need to do it once.
$conn->logLevel=3; // it os optional,
echo "<h2>orm</h2>";
$cities=CityRepo::recursive(['/_country_id','/_address'])->toList();
var_dump(CityRepo::base()->lastQuery);
echo
"<pre>";
var_dump($cities);
echo
"</pre>";
echo
"<h2>query</h2>";
$cities=CityRepo::query('select * from city inner join country on city.country_id=country.country_id');
echo
"<pre>";
var_dump($cities);
echo
"</pre>";
/*
$newCity=['city' => 'new city','country_id' => 105];
CityRepo::insert($newCity);
CityRepo::update($newCity);
CityRepo::delete($newCity);
CityRepo::deleteById(100);
*/