PHP code example of wtframework / dbal

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

    

wtframework / dbal example snippets


$response = DB::unprepared("SELECT * FROM users");

$response = DB::select()->from("users")->unprepared();

$response = DB::prepare("SELECT * FROM users WHERE user_id = ?");

$response = DB::select()->from("users")->where("user_id", "?")->prepare();

$response->bind(1);

$response->execute();

$response = DB::execute("SELECT * FROM users WHERE user_id = ?", 1);

$response = DB::select()->from("users")->where("user_id", 1)->execute();

DB::insert()->into("users")();

DB::get("SELECT * FROM users WHERE user_id = ?", 1);

DB::select()->from("users")->where("user_id", 1)->get();

$response->get();

DB::all("SELECT * FROM users");

DB::select()->from("users")->all();

$response->all();

DB::insert()->into("users")->execute();

DB::insertID();

$response = DB::update()->table("users")->set('active', 1)->execute();

$response->affectedRows();

DB::beginTransaction();
DB::commit();
DB::rollBack();

DB::transaction(function ()
{

  DB::insert()->into("users")->execute();

  // ...

});

$response = DB::connection("mirror")->select()->from("users")->where("user_id", 1)->get();

use WTFramework\DBAL\DB;

DB::select();
DB::insert();
DB::replace();
DB::update();
DB::delete();
DB::truncate();

DB::create();
DB::alter();
DB::drop();
DB::createIndex($name);
DB::dropIndex($name);

DB::bind($value);
DB::column($name);
DB::constraint($name);
DB::cte($name, $stmt);
DB::index($name);
DB::outfile($path);
DB::partition($name);
DB::raw($string);
DB::subpartition($name);
DB::subquery($stmt);
DB::table($name);
DB::upsert();
DB::window($name);

use WTFramework\DB\DB;

DB::macro('count', function (string $table)
{

  return static::select()
  ->column('COUNT(*) AS counter')
  ->from($table)
  ->get()
  ->counter;

});

DB::count('users');