Simple PHP MySQL database class for secure CRUD operations. Easily create, read, update, and delete records with minimal code.
If you are looking for a simple way to connect to your MySQL database using PHP and perform CRUD operations (Create, Read, Update, Delete), then PHP Simple Database Class is the right tool for you.
With this class, you can quickly build secure and powerful web applications using minimal code.
At the top of your PHP page (AJAX or include file), add:
$db_conn = array(
'host' => 'localhost',
'user' => 'root',
'pass' => '',
'database' => 'test',
);
$db = new SimpleDBClass($db_conn);
Inside the class file, you will notice:
// To show query error messages set on
// To hide them set off
public $ShowQryErrors = 'on';
During development and testing, keep this setting turned on so you can identify errors quickly.
Once your application is ready for production, switch it to off.
There are 5 main query functions:
There is also 1 important security function:
It is highly recommended that you sanitize all user data before inserting it into your database.
Retrieve rows from your database table.
$db->select("select * from users");
This returns all rows from the users table.
$user_id = $db->CleanDBData($_POST['user_id']);
$db->select("
select * from users
where user_id='$user_id'
");
$insert_arrays = array(
'user_id' => $db->CleanDBData($UserID),
'user_email' => $db->CleanDBData($UserEmail),
'user_password' => $db->CleanDBData($UserPassword),
);
$db->Insert('users', $insert_arrays);
Always hash your passwords before storing them into your database.
$array_fields = array(
'userid' => $db->CleanDBData($UserID),
'sitename' => $db->CleanDBData($UserSite),
);
$array_where = array(
'rec_id' => $RecID,
);
$db->Update(
$strTableName,
$array_fields,
$array_where
);
$array_where = array(
'site_name' => $site_name,
'user_email' => $user_email,
);
$Qry = $db->Delete(
$tabl_name,
$array_where
);
This PHP Simple Database Class was built to help developers create secure and powerful applications faster without dealing with unnecessary complexity.
If you want a lightweight way to handle MySQL CRUD operations using PHP, this class can save you a lot of development time.
You finish a project, get paid, and then it's back to finding the next client.
Month after month, the cycle repeats.
That's why many web developers never build real financial freedom—even though they're highly skilled.
The developers creating long-term wealth are using those same skills to build SaaS products, plugins, and digital tools that generate recurring income.
What if your next project could pay you more than once?
Learn How To Build Monthly Income →