1. Go to this page and download the library: Download primal/record library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
primal / record example snippets
class ExampleRecord extends \Primal\Database\MySQL\Record {
protected $tablename = 'example_table';
}
$pdo = new PDO("mysql:host=localhost;dbname=test", 'username', 'password');
$row = new ExampleRecord($pdo);
$row['column_1'] = "Foo";
$row = new ExampleRecord($pdo);
$row->column_1 = "Foo";
$row = new ExampleRecord($pdo);
$row['column_1'] = "Foo";
$row['column_2'] = 16;
$row['date_column'] = new DateTime('yesterday');
$row->save();
//$row['id'] now contains the auto-incremented primary key value.
$row = new ExampleRecord($pdo);
$row['id'] = 2;
$row['column_2'] = 16;
$row['date_column'] = 'now'; //Record will automatically parse strings into DateTime values for date column types (`DATE`, `DATETIME`, `TIMESTAMP`).
$row->save();
// only `column_2` and `date_column` on the row keyed with an id of 2 will be updated, all other columns will remain unchanged.
$row = new ExampleRecord($pdo);
if ($row->load(5)) {
$row->set('column_2', $new_value);
}
$row = new ExampleRecord($pdo);
if ($row->load(2)) {
//$row found a table row where the `id` column (the primary key) contained 2.
} else {
//No row was found that matched that primary key value.
}
$user = new User($pdo, array('email'=>'[email protected]'));
if ($user->found) {
// user code
}