PHP code example of restful-template / sql-manager
1. Go to this page and download the library: Download restful-template/sql-manager 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/ */
use RESTfulTemplate\SQLManager as SMan;
$db = new SMan( $dbInfo );
$tableName = "cars";
$data = $db->select( $tableName );
// $data contains an array of database result rows
use RESTfulTemplate\SQLManager as SMan;
$db = new SMan( $dbInfo );
$tableName = "cars";
$data = $db->select( $tableName, [ "id, year" ] );
// $data contains the two requested columns (id and year) for each row in cars table
$data = $db->select( $tableName, [], [ "year" => "2010" ] );
// $data contains rows from cars table where column year has value 2010
use RESTfulTemplate\SQLManager as SMan;
$body = [
"model" => "new model",
"brand" => "some brand",
"year" => "2020"
];
$db = new SMan( $dbInfo );
$tableName = "cars";
$result = $db->insert( $tableName, $body );
// $result is true if everything ok and false if some error happens.
use RESTfulTemplate\SQLManager as SMan;
$body = [
"model" => "correct model",
];
$where = [ "id" => 1 ];
$db = new SMan( $dbInfo );
$tableName = "cars";
$result = $db->update( $tableName, $body, $where );
// $result is true if everything ok and false if some error happens.
use RESTfulTemplate\SQLManager as SMan;
$db = new SMan( $dbInfo );
$tableName = "cars";
$where = [ "id" => 1 ];
$result = $db->delete( $tableName, $where );
// $result is true if everything ok and false if some error happens.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.