1. Go to this page and download the library: Download centamiv/concrete 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/ */
centamiv / concrete example snippets
use Concrete\Database;
use Concrete\Connection\MysqlDriver;
Database::init(new MysqlDriver(), '127.0.0.1', 'my_database', 'root', 'password');
use Concrete\Database;
use Concrete\Connection\SqliteDriver;
// Second parameter is the file path (or ':memory:' for in-memory)
Database::init(new SqliteDriver(), '/path/to/database.sqlite');
use Concrete\Database;
use Concrete\Connection\PostgresDriver;
Database::init(new PostgresDriver(), '127.0.0.1', 'my_database', 'postgres', 'password');
use Concrete\Database;
use Concrete\Connection\SqlServerDriver;
Database::init(new SqlServerDriver(), 'localhost', 'my_database', 'sa', 'password');
namespace App\Models;
use Concrete\Model;
class User extends Model
{
public const TABLE = 'users';
// Optional: column name constants for type-safe references
public const COL_ID = 'id';
public const COL_NAME = 'name';
public const COL_EMAIL = 'email';
public const COL_AGE = 'age';
public const COL_ACTIVE = 'active';
public const COL_ROLE_ID = 'role_id';
public const COL_CREATED_AT = 'created_at';
}
class Order extends Model
{
public const TABLE = 'orders';
public const PRIMARY_KEY = 'order_code'; // custom single key
}
class OrderItem extends Model
{
public const TABLE = 'order_items';
public const PRIMARY_KEY = ['order_id', 'product_id']; // composite key
}
$user = new User();
$user->set(User::COL_NAME, 'Mario Rossi')
->set(User::COL_EMAIL, '[email protected]')
->save();
echo $user->get(User::COL_ID); // auto-incremented ID
$sql = User::query()
->where(User::col(User::COL_ACTIVE), '=', 1)
->sql();
// SELECT * FROM users WHERE users.active = :users_active0
use Concrete\Database;
$stmt = Database::getConnection()->query('SELECT COUNT(*) as n FROM users GROUP BY age');
$rows = $stmt->fetchAll();
use Concrete\Query\Builder;
$builder = new Builder();
$users = $builder->table(User::class)
->where(User::col(User::COL_ACTIVE), '=', 1)
->get();
// app/Providers/AppServiceProvider.php
use Concrete\Database;
use Concrete\Connection\MysqlDriver;
use Illuminate\Support\Facades\DB;
public function boot(): void
{
Database::initFromPDO(
DB::connection()->getPdo(),
new MysqlDriver()
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.