A Simple Create,Read,Update,Delete Library for your PHP Web App. Basically, there wouldn't be any need to tinker with annoying Query Codes. Leverages Both MYSQLi and PDO.
First install Composer using
composer install
Then Require it using
composer require scrud/scrud
Which will then be added to your Composer.json dependencies.
Or
- Clone this Repo which will then be stored in your chosen directory as Simple_CRUD
git clone https://github.com/kofacts/Simple_CRUD.git"
-
Open the File
-
Locate the src/ directory and Open the config.php
-
Fill in the necessary details and DB_Type. MYSQLI or PDO.
$connectDetails=[
"hostname"=>"hostname",
"username"=>"username",
"password"=>"password",
"DB_NAME"=>"database name",
"connect_type"=>strtoupper("pdo or mysqli"),
];
- Inside your Main Page, say index.php, instantiate a Scrud Object.
$scrud= new Scrud;
- Now you Have done the needful, What can you do with all this.
- create($tablename,$fields) : The tablename is the name of the Tablename you wish to add Data to, while the fields are the array of data you wish to insert values into. From the code below, the user_details is the tablename, while the array are yes, array of values you wish to insert data into.
$scrud->create("user_details",array("username"=>"Ricesss","password"=>"pico4421ss"));
- get($tablename) : params is just $tablename. This would get all fields from DB. Simple instantiate the Scrud Class. eg
$posts=$scrud->get("user_details");
And then loop through all the fields.
foreach($posts as $row)
{
echo $row['username'];
}
- get_where($tablename,$id,$value): This would accept params tablename,id/field and the value you wish to get. To use, simply do
$value=$scrud->get_where($tablename,$id,$value)
And then use
echo $value['username'];
- update($tablename,$field,$id,$value); This would accept params $tablename,$field [arrays],id to be update and value. To use, simply do,
$scrud->update("user_details",array("username"=>"Rapheal","password"=>"skjf..anything"),"id",1);
- delete($tablename,$id,$value): This would accept params $tablename,$id to delete and then value. To Use, Simply do,
$scrud->delete("user_details","id",2);
The Concept is inspired by Codeigniter's Sleek Query System. Make it simple, and very simple has always been the name.
There are so many features that should be added to this platform. Hey, Don't just leave, you can always contribute by pulling a request.
Nah, Nada, Don't thank Me. Actually, you can thank me by Staring. Em, 😄 I think that is just it.
PS: Some Basic Touches still going on.
MIT