dev-master
9999999-dev https://sintret.comsintret project with simple pdo and autoloading simple
MIT
The Requires
- php >=5.4.0
- sintret/pdo dev-master
by Andy Fitria
pdo mysql generate project
sintret project with simple pdo and autoloading simple
Generate PHP Application with single command and PDO wrapper, (*1)
composer create-project -s dev sintret/freelancer your-directory
in your page you must to include autoload, (*2)
require(__DIR__ . '/autoload.php');
this is example to load model in folder models, you must to extends from sintret\pdo\Db, (*3)
models/BaseModel.php, (*4)
class BaseModel extends sintret\pdo\Db{ public function __construct() { parent::__construct(HOST, DB_NAME, DB_USER, DB_PASS); } }
index.php, (*5)
$db = new BaseModel; $songs = $db->query("SELECT * FROM song"); echo " < pre>";print_r($songs);
This method always returns only 1 row., (*6)
<?php // Fetch a row $ages = $db->row("SELECT * FROM song WHERE id = :id", array("id"=>"1"));
This method returns only one single value of a record., (*7)
<?php // Fetch one single value $db->bind("id","3"); $firstname = $db->single("SELECT title FROM song WHERE id = :id");
|title , (*8)
Aku disini |
<?php // Fetch a column $names = $db->column("SELECT title FROM song"); ### Delete / Update / Insert When executing the delete, update, or insert statement by using the query method the affected rows will be returned. ```php <?php // Delete $delete = $db->query("DELETE FROM song WHERE id = :id", array("id"=>"1")); // Update $update = $db->query("UPDATE song SET title = :f WHERE id = :id", array("f"=>"Jan","id"=>"2")); // Insert $insert = $db->query("INSERT INTO song(title,status) VALUES(:title,:status)", array("title"=>"Vivek","status"=>"20")); // Do something with the data if($insert > 0 ) { return 'Succesfully created a new person !'; }
This example create simple class Song look like this following, (*9)
class Song extends sintret\pdo\Crud { protected $table = 'song'; # Primary Key of the table protected $pk = 'id'; // ling to class db connection here public $className = 'BaseModel'; }
Example for create new Song code will create new record song like these following code:, (*10)
$model = new Song(); $model->title = 'Disaat Aku Tersakiti'; $model->artist = 'Dadali'; $model->album = ' Disaat Aku Tersakiti'; $model->createDate = date("Y-m-d H:i:s"); $model->status = 1; $model->create();
Example for find Song code will create new record song like these following code:, (*11)
$model = new Song(); $model->find(1); echo $model->title; echo $model->artist;
or with multiple, (*12)
$model = new Song(); $model->find(['artist '=>'Dadali','status'=>1]); echo $model->title; echo $model->artist;
Example for find Song code will create new record song like these following code:, (*13)
$model = new Song(); $model->status = 2; $model->rate = 66; $model->save(3);
Example for delete Song code will create new record song like these following code:, (*14)
$model = new Song(); $model->delete(1);
Example for delete Song code will create new record song like these following code:, (*15)
$model = new Song(); $model->all(); echo "<pre>"; print_r($model);
Example for save with array Song code will create new record song like these following code:, (*16)
$model = new Song(['title' => 'I can teach you', 'artist' => 'bon jovi','status'=>1]); $model->create(); echo "<pre>"; print_r($model);
sintret project with simple pdo and autoloading simple
MIT
pdo mysql generate project