PHP code example of fulldecent / thin-pdo

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

    

fulldecent / thin-pdo example snippets



//__contruct Method Declaration
public function __construct($dsn, $user="", $passwd="") { }

//MySQL
$db = new db("mysql:host=127.0.0.1;port=8889;dbname=mydb", "dbuser", "dbpasswd");

//SQLite
$db = new db("sqlite:db.sqlite");


//delete Method Declaration
public function delete($table, $where, $bind="") { }

//DELETE #1
$db->delete("mytable", "Age < 30");

//DELETE #2 w/Prepared Statement
$lname = "Doe";
$bind = array(
    ":lname" => $lname
)
$db->delete("mytable", "LName = :lname", $bind);


//insert Method Declaration
public function insert($table, $info) { }

$insert = array(
    "FName" => "John",
    "LName" => "Doe",
    "Age" => 26,
    "Gender" => "male"
);
$db->insert("mytable", $insert);


//run Method Declaration
public function run($sql, $bind="") { }

//MySQL
$sql = <<<STR
CREATE TABLE mytable (
    ID int(11) NOT NULL AUTO_INCREMENT,
    FName varchar(50) NOT NULL,
    LName varchar(50) NOT NULL,
    Age int(11) NOT NULL,
    Gender enum('male','female') NOT NULL,
    PRIMARY KEY (ID)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
STR;
$db->run($sql);

//SQLite
$sql = <<<STR
CREATE TABLE mytable (
    ID INTEGER PRIMARY KEY,
    LName TEXT,
    FName TEXT,
    Age INTEGER,
    Gender TEXT
)
STR;
$db->run($sql);


//select Method Declaration
public function select($table, $where="", $bind="", $fields="*") { }

//SELECT #1
$results = $db->select("mytable");

//SELECT #2
$results = $db->select("mytable", "Gender = 'male'");

//SELECT #3 w/Prepared Statement
$search = "J";
$bind = array(
    ":search" => "%$search"
);
$results = $db->select("mytable", "FName LIKE :search", $bind);


//setErrorCallbackFunction Method Declaration
public function setErrorCallbackFunction($errorCallbackFunction, $errorMsgFormat="html") { }

//The error message can then be displayed, emailed, etc within the callback function.
function myErrorHandler($error) {
}

$db = new db("mysql:host=127.0.0.1;port=8889;dbname=mydb", "dbuser", "dbpasswd");
$db->setErrorCallbackFunction("myErrorHandler");
/*
Text Version
$db->setErrorCallbackFunction("myErrorHandler", "text");

Internal/Built-In PHP Function
$db->setErrorCallbackFunction("echo");
*/
$results = $db->select("mynonexistingtable");


//update Method Declaration
public function update($table, $info, $where, $bind="") { }

//Update #1
$update = array(
    "FName" => "Jane",
    "Gender" => "female"
);
$db->update("mytable", $update, "FName = 'John'");

//Update #2 w/Prepared Statement
$update = array(
    "Age" => 24
);
$fname = "Jane";
$lname = "Doe";
$bind = array(
    ":fname" => $fname,
    ":lname" => $lname
);
$db->update("mytable", $update, "FName = :fname AND LName = :lname", $bind);