MySQLi Prepared Statements is a lightweight portable PHP class that will allow you to easily run prepared statements.
Whether it’s SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, REPLACE or any other MySQL query you want to run; this script will handle it.
This script supports descriptive error handling, making debugging easier. Using the destruct magic method, automatically after an instance of the class is no longer needed, the MySQLi connection is closed and disconnected, freeing up resources.
Check out the live demo to see the documentation.
Connect to a databaseWhen instantiating the class a data, you simply pass in your MySQL connection details in order to connect to the database. As you can create as many instances as you want, you can connect to as many databases as you want using this class:
$easypreparedstatements = new easyPreparedStatements($dbhost, $dbuser, $dbpassword, $dbname);
Select ExampleGet blog posts from the tech category in an array in just one line of code:
$blogposts = $easypreparedstatements->query("SELECT id, title, post FROM posts WHERE `category`= ?", array("tech"));
Insert ExampleInsert a new blog post into a MySQL database in one line of code. The script will automatically return the amount of affected rows:
$easypreparedstatements->query("INSERT INTO `posts` (`id`, `title`, `post`, `time`, `category`) VALUES ('?', '?', '?', '?', '?', '?')", array($id, "Title", "Post", $time, "tech"));