<?php
Class Dbda
{
Public $host = "localhost"; Server address
Public $uid = "root"; User name
Public $pwd = "123"; Password
Public $dbconnect; Connection object
Ways to manipulate databases
$SQL represents the SQL statement that needs to be executed
$type represents the type of SQL statement, 1 represents the query, 2 represents
$dbname represents the name of the database to manipulate
If the query returns a two-dimensional array
Returns TRUE or False if additions and deletions are changed
function Query ($sql, $type =1, $dbname = "Student")
{
Connecting objects
$this->dbconnect = new Mysqli ($this->host, $this->uid, $this->pwd, $dbname);
Judging if there is an error
if (!mysqli_connect_error ())
{
If the connection executes the SQL statement successfully
$result = $this->dbconnect->query ($sql);
Judging by the type of statement
if ($type ==1)
{
Returns a two-dimensional array if it is a query statement
return $result->fetch_all ();
}
Else
{
If it is a different statement, return Ture or False
return $result;
}
}
Else
{
Return "link Failed";
}
}
}
?>
PHP uses classes to make database connections