PHP code example of tkaratug / titan-db
1. Go to this page and download the library: Download tkaratug/titan-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/ */
tkaratug / titan-db example snippets
$config = [
'db_driver' => 'mysql',
'db_host' => 'localhost',
'db_user' => 'root',
'db_pass' => '',
'db_name' => 'test',
'db_charset' => 'utf8',
'db_collation' => 'utf8_general_ci',
'db_prefix' => ''
];
$db = TitanDB::init($config);
$records = $db->select('user_id, first_name, last_name, email')
->from('users')
->where('active', 1)
->order_by('user_id', 'asc')
->get()
->results();
var_dump($records);
// Get all columns
$records = $db->get('users')->results();
var_dump($records);
// Get all columns in a row
$db->where('user_id', 5);
$records = $db->get('users')->row();
var_dump($records);
// JOIN Usage
$record = $db->select('t1.user_id, t1.first_name, t1.last_name, t2.group_name')
->from('users as t1')
->join('groups as t2', 't1.user_id=t2.user_id', 'left')
->where('t1.active', 1)
->get()
->results();
var_dump($record);
// INSERT Usage
$data = [
'first_name' => 'John',
'last_name' => 'Doe',
'email' => '[email protected] '
];
$db->insert('users', $data);
// UPDATE Usage
$data = [
'first_name' => 'John',
'last_name' => 'Doe',
'email' => '[email protected] '
];
$db->where('user_id', 5);
$db->update('users', $data);
// DELETE Usage
$db->where('user_id', 5);
$db->delete('users');