PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Eric AGNEL   Simple PHP PDO API   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Read me
Class: Simple PHP PDO API
Perform common database operations using PDO
Author: By
Last change:
Date: 1 year ago
Size: 1,668 bytes
 

Contents

Class file image Download

SApi

Simple CRUD api system.

About

This is a simple API class meant to be easy to use without to much configuration.

Basic Usage

The minimum setup needed to use the Logger class.

_SQL request without parameters_


<?php
require_once("vendor/autoload.php");

use Kuran\SApi\Api;

$db = new PDO();

$sqlQuery = "SELECT
                    users.name,
                    users.email,
                    users.address
                FROM users";

$queryParams = [];

$api = new Api($db);

$api->setQueryString($sqlQuery);

echo $api->readAll($queryParams);


_SQL request with named parameters_


$sqlQuery = "SELECT
                    users.name,
                    users.email,
                    users.address
                FROM users
                WHERE users.id = :id
                AND users.name = :name";

$queryParams = ["id" => 2, "name" => "username"];

_SQL request with dynamic parameters_


$sqlQuery = "SELECT
                    users.name,
                    users.email,
                    users.address
                FROM users
                WHERE users.id = ?
                AND users.name = ?";

$queryParams = [2, "username"];

Class methods


// readAll().
// Will fetch all matching rows from the database.
$api->readAll(array());

//readOne().
// Will fetch one matching row from the database.
$api->readOne(array());

//create().
// Insert data to the database
$api->create(array());

//update()
// Will update a row from the database.
$api->update(array());

//delete()
// Will delete an entry from the database
$api->delete(array());