PHP code example of axisstudios / db-record

1. Go to this page and download the library: Download axisstudios/db-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/ */

    

axisstudios / db-record example snippets


// insert a record, as the 'id' parameter is not present
$t = new DbRecordTable($db, "table0");
$id = $t->insert(["title" => "New title", "created_at" => date("Y-m-d H:i:s")]);
echo "Inserted record ID: $id";

$t = new DbRecordTable($db, "table0");
$t->update(["title" => "New title", "created_at" => date("Y-m-d H:i:s")], 1);

$t = new DbRecordTable($db, "table0");
// if $recordId is null, insert a new record and returns the id,
// otherwise update the current record
$recordId = $t->save(["title" => "New title", "created_at" => date("Y-m-d H:i:s")], $recordId);
echo $recordId;

$t = new DbRecordTable($db, "table0");
list($title, $createdAt) = $t->select(["title", "created_at"], 1);
echo "title: $title, Created at: $createdAt";

$t = new DbRecordTable($db, "table0");
$t->delete(1);

// the following example updates table0, table1, table2 and table3 at the same time
$t = new DbRecordTable($db, "table0");
$t->update(
  [
    "title" => "My title",
    "created_at" => date("Y-m-d H:i:s"),
    "table1.title" => "Title 1",
    "table2.title" => "Title 2",
    "table3.title" => "Title 3"
  ],
  1
);

$t = new DbRecordTable($db, "table0");
list($title, $createdAt, $t1Title, $t2Title, $t3Title) = $t->select(
  [
    "title",
    "created_at",
    "table1.title",
    "table2.title",
    "table3.title"
  ],
  1
);
echo "title: $title, created_at: $createdAt, table1.title: $t1Title, table2.title, $t2Title, table3.title, $t3Title";

$t = DbRecordTable($db, "table0");
list($title, $t1Title, $t2Title) = $t->select(
  [
    "title",
    "table1.title",
    "table2[table1.table2_id].title"
  ],
  1
);