July 23, 20197 yr So it's been awhile this i posted something I've built on here but thought someone may find this database class useful or build onto it. Here is the project on github https://github.com/webdeveloper73/MysqliDB/blob/master/MysqliDB.php here is a basic example... Example <?php //Connect to database $db = new MysqliDB("mysql_host","mysql_username","mysql_password","mysql_database"); //SELECT * FROM `posts` WHERE id > 10 AND id < 55 ORDER BY `id` DESC $db->select() ->from("posts") ->whereByArray(array("id >" => 10,"id <" => 55)) ->order_by("id","DESC") ->run(); if($db->num_rows() > 0) { foreach($db->result() as $row): echo $row->postContent."<br />"; endforeach; }else{ echo "No posts to show"; } Example 2 <?php //SELECT * FROM `posts` WHERE id > 5 //Pass false to the last parameter to prevent escaping fields with back ticks //The run method executes the built query $db->select()->from("posts")->where("id",5,">",null,false)->run(); Example 3 multiple where conditions //SELECT * FROM `posts` WHERE `id` = 7 OR `id` = 9 LIMIT 1 $db->select()->from("posts")->where("id",7)->where("id",9,null,"OR")->limit(1)->run(); Example 4 whereIN method //SELECT * FROM `users` WHERE `id` IN('5','8','1','2') $db->select()->from("users")->whereIN("id",["5","8","1","2"])->order_by("id","DESC")->run(); This class includes quite a few more methods here is the list... rawQuery() insert() insertID() update() delete() escape() num_rows() select() selectCustom() from() where() whereCustom() whereByArray() whereIN() whereNotIN limit() order_by() result() row() run() getLastQuery() more functionality will be added at a later date
Create an account or sign in to comment