<?PHPclassdbda{ Public $host= "localhost";//Server Address Public $uid= "Root";//user name of the database Public $pwd= "123";//Database Password//Execute SQL statement, return the corresponding result of the function//$sql is to execute the SQL statement//$type is the type of SQL statement, 0 for adding or deleting, 1 for the query//$DB represents the database to operate Public functionQuery ($sql,$type=1,$db= "MyDB") { //Connecting Objects $conn=NewMysqli ($this->host,$this->uid,$this->pwd,$db); //determine if the connection is successful!Mysqli_connect_error() or die("Connection Failed! "); //Execute SQL statement $result=$conn->query ($sql); //determine the type of SQL statement if($type==1) { //If the query statement returns a two-dimensional array of result sets return $result-Fetch_all (); } Else { //returns TRUE or False if it is a different statement return $result; } } }
Database wrapper into Class