Database Operation Handling in PHP
Not the best approach. Just one approach. At least to help with thinking. to start with.
//you can keep database parameters in a file [text file or xml file].
Create two users one with only read permission, another with read-write permission.
Use read user related connection in read only operations.
read-write user related database connection should be used only when writing is associated
//database user with read only permission
$roUser = "";
$roPassword = "";
//database user with read-write permission
$rwUser = "";
$rwPassword = "";
//database and the host $host = "localhost";
$database = "your_database";
//read only handle to database
$dbhReadOnly = null;
//read-write handle to database
$dbhReadWrite = null;
//read-write connection creation
global $rwUser, $rwPassword, $host, $database;
//connect to db with user that has read-write permission to the database
$dbhReadWrite = mysqli_connect( "$host", "$rwUser", "$rwPassword", "$database");
//read-only connection creation
global $roUser, $roPassword, $host, $database;
//connect to the database with a user that has only read permission to the database
$dbhReadOnly = mysqli_connect( "$host", "$roUser", "$roPassword", "$database");
//read-only connection - can be used from other php files
$dbhReadWrite = getDbhReadWrite();
$dbhReadOnly = getDbhReadOnly();