Not the best approach. Just one approach. At least to help with thinking. to start with.
< ?php
//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";
?>
< ?php
//read only handle to database
$dbhReadOnly = null;
//read-write handle to database
$dbhReadWrite = null;
//read-write connection creation
function getDbhReadWrite(){
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"); //var_dump($dbhReadWrite);
if (!($dbhReadWrite))
return null;
return $dbhReadWrite;
}
//read-only connection creation
function getDbhReadOnly(){
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");
if (!($dbhReadOnly))
return null;
return $dbhReadOnly;
}
//read-only connection - can be used from other php files
$dbhReadWrite = getDbhReadWrite();
//read-write connection-
$dbhReadOnly = getDbhReadOnly();
?>
From: http://sitestree.com/?p=5135
Categories:16
Tags:
Post Data:2007-01-01 17:15:46
Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a>
In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
<a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>
