PHP code example of geekcow / dbcore
1. Go to this page and download the library: Download geekcow/dbcore 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/ */
geekcow / dbcore example snippets
class User extends Entity {
private $name_of_the_table = [
'id' => ['type' => 'int', 'unique' => true, 'pk' => true],
'username' => ['type' => 'string', 'length' => 32, 'unique' => true],
'email' => ['type' => 'string', 'length' => 255]
];
public function __construct() {
parent::__construct($this->name_of_the_table, get_class($this));
}
}
$user = new User();
$result = $user->fetch();
$user->fetch_id(['id' => '1']);
$user = new User();
$user->columns['username'] = 'john_doe';
$user->columns['email'] = '[email protected] ';
$id = $user->insert();
$user->fetch_id(['id' => '1']);
$user->columns['email'] = '[email protected] ';
$user->update();
$user->fetch_id(['id' => '1']);
$user->delete();
// Step 1: Instantiate the QuerySelectBuilder class
$selectBuilder = new QuerySelectBuilder();
// Step 2: Specify the table
$selectBuilder->withTable('users');
// Step 3: Specify the columns
$selectBuilder->withColumns(['id', 'username', 'email']);
// Step 4: (Optional) For counting rows, uncomment the next line
// $selectBuilder->forCount(true);
// Step 5: Specify grouping criteria (if needed)
// $selectBuilder->withGroup('department_id');
// Step 6: Add JOIN clause (if needed)
// For demonstration, assuming we're not adding a JOIN clause here
// Step 7: Generate the SQL query string
$sqlQuery = $selectBuilder->toSql();
echo $sqlQuery;