1. Go to this page and download the library: Download fullstackpe/micro-db 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/ */
fullstackpe / micro-db example snippets
use micro\db\ActiveRecord;
class Book extends ActiveRecord {
public static function tableName()
{
return 'book';
}
public static function dbConnection()
{
$servername = "127.0.0.1";
$username = "root";
$password = "fullstack";
$database = "mysql";
return new \micro\db\Connection($servername, $username, $password, $database);
}
}
// Create a new book
$book = new Book();
$book->title('This is the title of my book');
$book->save();
// fetchs all books
$books = Book::find()->all();
foreach($books as $book) {
echo $book->title;
}
// search for one book
$condition = [
['=', 'id', '1']
];
$book = Book::find()->where($condition)->one();
echo $book->title