A quick,easy and safe way of accessing Mysql-like databases from within a PHP program

Overview

Mysqli-Safe

A simple, easy-to-use and secure way of accessing a Mysql database from within your PHP programs

Build Status

Mysqli-safe is a wrapper around the mysqli extension in PHP that bundles together the extension itself and Mysql prepared statements into one neat and succint API that's very easy to use.

In fact, you can perform an initial database query in just three easy steps:

  1. Open a database connection by creating a mysqli_safe object.
  2. Set the query and its parameters by calling the set method of the created object.
  3. Perform the query!

Example

$db = new mysqli_safe('localhost' , 'username' , 'password' , 'database');

$res = $db->set("SELECT * FROM table WHERE id = ? AND name = ?" , $id , $name);

$result = $db->query();

Features

In addition to providing a short and concise API, the mysqli_safe class also offers the following features:

1.Object Re-use

With mysqli_safe, you do not really need to create a new object in order to connect to a new database.Instead, just call the connect method and pass in the details of the new database, and the class will handle the rest for you. ( Including closing any previously opened db connection)

Example

$res = $db->connect('localhost' , 'new_username' , 'password' , 'new_database');

2.Compatibility

Mysqli_safe is also backwards compatible with any existing programs that use the mysqli extension. To migrate to using this wrapper class, just add a set method and pass in the existing query and its parameters and then call the query method. The rest of the program should continue working without altering anything else.

Example

before

...

$result = $db->query("SELECT * FROM table WHERE id = '$id' AND name = '$name');

...

after

...

$setresult = $db->set("SELECT * FROM table WHERE id = ? AND name = ? , $id , $name);

$result = $db->query();

...

3.Type Deduction

With mysqli_safe you do not have to worry about passing the correct type string like in the traditional way of creating prepared statements. The class will deduce the types for you and create the correct string when you call the set method. However, if you do not want this behaviour, you can always turn this feature off by calling the setopt method and passing your own type string.

Example

$res = $db->setopt(DEDUCE_TYPE , false , "is");

$setresult = $db->set("SELECT * FROM table WHERE id = ? AND name = ? , $id , $name);

$result = $db->query();

4.Query Statement Re-use

Mysqli_safe also allows you to re-use the same query statement and parameters across mutiple databases, if they have the same structure. All you have to to is to enable the REUSE_STMT option and the class will do the rest for you.

Example

$setresult = $db->set("SELECT * FROM table WHERE id = ? AND name = ? , $id , $name);

$result = $db->query();

$res = $db->setopt(REUSE_STMT , true);

$res = $db->connect('localhost' , 'new_username' , 'password' , 'new_database');

$res = $db->query();

5.Built-in Protection Against Some Common Web Attacks

Mysqli_safe uses Mysql's prepared statements and PHP's built-in htmlspecialchars function to guarantee protection against SQL injection and XSS attacks respectively, when reading from or writing to your database. This ensures that each and every one of your database accesses is secure with the programmer having to think much about it, allowing him/her to focus on the core logic of his/her application.

You might also like...
Database Transferring Program Using PHP

database-transferring-program Database Transferring Program Using PHP Demo: http://php-form.ga/database-transferring/ How To Use Download XAMPP from h

This is the US hardened version of PHP-Nuke Titanium and is secure and safe
This is the US hardened version of PHP-Nuke Titanium and is secure and safe

This is the US hardened version of PHP-Nuke Titanium and is secure and safe. Built on PHP Version 7.4.30 - Forums - Blogs - Projects - Advanced Site Map - Web Links - Groups - Advanced Theme Support - Downloads - Advertising - Network Advertising - Link Back System - FAQ - Bookmark Vault - Private Virtual Cemetery - Loan Amortization - Image Hosting

BetterWPDB - Keeps you safe and sane when working with custom tables in WordPress.

BetterWPDB - Keeps you safe and sane when working with custom tables in WordPress.

A simple, type-safe, zero dependency port of the javascript fetch WebApi for PHP.
A simple, type-safe, zero dependency port of the javascript fetch WebApi for PHP.

A simple, type-safe, zero dependency port of the javascript fetch WebApi for PHP.

Make your PHP arrays sweet'n'safe

Mess We face a few problems in our PHP projects Illogical type casting (PHP's native implementation is way too "smart") Pointless casts like array =

A collection of type-safe functional data structures

lamphpda A collection of type-safe functional data structures Aim The aim of this library is to provide a collection of functional data structures in

The easiest way to match data structures like JSON/PlainText/XML against readable patterns. Sandbox:

PHP Matcher Library created for testing all kinds of JSON/XML/TXT/Scalar values against patterns. API: PHPMatcher::match($value = '{"foo": "bar"}', $p

A simple way to know if you are on the list of major security breaches like "HIBP", but it is specific for Iran.

Leakfa.com A simple way to know if you are on the list of major security breaches like "HIBP", but it is specific for Iran. Service content This produ

This component, based on the Symfony serializer and async-aws, is a human-readable and quick abstraction to easily store serialized objects in DynamoDB 🚀.

DynamoDB Storable This component, based on the Symfony serializer and async-aws, is a human-readable and quick abstraction to easily store serialized

Owner
Anthony Maina Njoroge
Coding Ninja!
Anthony Maina Njoroge
Skosmos is a web-based tool providing services for accessing controlled vocabularies, which are used by indexers describing documents and searchers looking for suitable keywords.

Skosmos is a web-based tool providing services for accessing controlled vocabularies, which are used by indexers describing documents and searchers looking for suitable keywords.

National Library of Finland 195 Dec 24, 2022
UMySQL is an extremely simple PHP library for communicating with MySQL databases with ease while keeping overhead to a bare minimum.

Uncomplicated MySQL UMySQL is an extremely simple PHP library for communicating with MySQL databases with ease while keeping overhead to a bare minimu

José Miguel Moreno 4 Oct 24, 2022
A tool for creating configurable dumps of large MySQL-databases.

slimdump slimdump is a little tool to help you create configurable dumps of large MySQL-databases. It works off one or several configuration files. Fo

webfactory GmbH 176 Dec 26, 2022
MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query and get result in a fastest way

Mysql Optimizer mysql optimizer also known as MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query

null 2 Nov 20, 2021
Kirby 3 Plugin for running jobs like cleaning the cache from within the Panel, PHP code, CLI or a cronjob

Kirby 3 Janitor Kirby 3 Plugin for running jobs. It is a Panel Button! It has jobs build-in for cleaning the cache, sessions, create zip-backup, pre-g

Bruno Meilick 68 Dec 21, 2022
BreadBooru is a light, quick, and easy to setup imageboard with themes, images, and video support

BreadBooru a bad imageboard, that has nothing to do with (dan/gel)booru, and yet still has booru in the name BreadBooru is a light, quick, and easy to

bread 2 Jan 22, 2022
Phalcon Builder - is a packaging system that make it easy and quick to build Phalcon packages such as rpms, debs, etc. Phalcon's distribution that hosted at PackageCloud.

Phalcon Builder - is a packaging system that make it easy and quick to build Phalcon packages such as rpms, debs, etc. Phalcon's distribution that hos

The Phalcon PHP Framework 26 Oct 7, 2022
A quick naked theme to demonstrate how easy it is to support Gutenberg using ACF blocks

ACF Gutenberg Demo Theme A quick naked theme to demonstrate how easy it is to support Gutenberg using ACF blocks demo.mp4 Files I have found a useful

Stirtingale 1 Oct 28, 2021
The Current US Version of PHP-Nuke Evolution Xtreme v3.0.1b-beta often known as Nuke-Evolution Xtreme. This is a hardened version of PHP-Nuke and is secure and safe. We are currently porting Xtreme over to PHP 8.0.3

2021 Nightly Builds Repository PHP-Nuke Evolution Xtreme Developers TheGhost - Ernest Allen Buffington (Lead Developer) SeaBeast08 - Sebastian Scott B

Ernest Buffington 7 Aug 28, 2022
🐘 A probe program for PHP environment (一款精美的 PHP 探針, 又名X探針、劉海探針)

Simplified Chinese | 简体中文 Traditional Chinese(Taiwan) | 正體中文(臺灣) Traditional Chinese(Hong Kong) | 正體中文(香港) Japanese | 日本語 ?? X Prober This is a probe

Km.Van 1.2k Dec 28, 2022