コード例 #1
0
ファイル: __mysql.php プロジェクト: vugluskr86/_autoservice
<?php

include_once dirname(__FILE__) . "/SimpleOrm.class.php";
$conn = new mysqli('localhost', 'grease_rat', 'grease_rat');
if ($conn->connect_error) {
    die(sprintf('Unable to connect to the database. %s', $conn->connect_error));
}
if (!$conn->set_charset("utf8")) {
    die(printf("Ошибка при загрузке набора символов utf8: %s\n", $conn->error));
}
SimpleOrm::useConnection($conn, 'grease_rat');
コード例 #2
0
ファイル: example.php プロジェクト: noetix/simple-orm
<?php

// Load parameters.
$params = parse_ini_file(sprintf('%s/parameters.ini', __DIR__), true);
// Include the SimpleOrm class
include 'SimpleOrm.class.php';
// Connect to the database using mysqli
$conn = new mysqli($params['database']['host'], $params['database']['user'], $params['database']['password']);
if ($conn->connect_error) {
    die(sprintf('Unable to connect to the database. %s', $conn->connect_error));
}
// Tell SimpleOrm to use the connection you just created.
SimpleOrm::useConnection($conn, $params['database']['name']);
// Define an object that relates to a table.
class Blog extends SimpleOrm
{
}
// Create an entry.
$entry = new Blog();
$entry->title = 'Hello';
$entry->body = 'World!';
$entry->save();
// Use the object.
printf("%s\n", $entry->title);
// prints 'Hello';
// Dump all the fields in the object.
print_r($entry->get());
// Retrieve a record from the table.
$entry = Blog::retrieveByPK($entry->id());
// by primary key
// Retrieve a record from the table using another column.