abbe98 / simple-pdo
A simpe PDO class for MariaDB and MySQL
2.1.0
2017-02-09 11:10 UTC
Requires
- php: >=5.6.0
This package is not auto-updated.
Last update: 2024-12-21 18:13:57 UTC
README
Secure and simple library for PHP's PDO class.
Installation
Install the composer package.
composer require abbe98/simple-pdo
In define your database connection/user details using constants:
const HOST = '' // the IP of the database const DBNAME = '' // the database name to be used const USERNAME = '' // the username to be used with the database const PASSWORD = '' // the password to be used with the username
Usage Examples
Create new SimplePDO instance and open a connection:
$database = SimplePDO::getInstance();`
If there is already a open connection that one will be used automatically.
Query database and return a single row:
$database = SimplePDO::getInstance(); $database->query("SELECT `column` FROM `table` WHERE `columnValue` = :id"); $database->bind(':id', 123); $result = $database->single();
Query database and return multiply rows:
$database = SimplePDO::getInstance(); $database->query("SELECT * FROM `table`"); $result = $database->resultSet();
Insert new row in database:
$database = SimplePDO::getInstance(); $database->query("INSERT INTO `users` (name, email) VALUES (:name, :email)"); $database->bind(':name', $name); $database->bind(':name', $email); $database->execute();
Update existing row:
$database = SimplePDO::getInstance(); $database->query("UPDATE `users` SET `name` = :name WHERE `id` = :id"); $database->bind(':name', $newName); $database->bind(':id', $id); $database->execute();