Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 922 Bytes

README.md

File metadata and controls

27 lines (19 loc) · 922 Bytes

php-safe-builder

PHP safe string builder. Builds SQL query.

builder

Icon by Freepik - Flaticon

Why this library?

PHP does not provide the capability to securely build SQL strings statically. One would need to rely on PDO or MySQLi, but what if there isn't a database to connect to and you just need to construct an escaped query?

An example use case: constructing an SQL string to be executed via STDIN in a mysql client on a remote server via SSH.

Usage

# Instantiate the object
$sqlBuilder = new SqlBuilder();

# Write the query template
$query = 'SELECT * FROM this_table WHERE this_field = :value AND other_field = :value2';

# Safely build the query
$safeQuery = $sqlBuilder->build($query, [
':value' => 'This is a value',
':value2' => 123
]);