PHP connection database is generally used in an object-oriented approach, you need to create an object, that is, build a Connection object, and then write the SQL statement, (add to delete), and finally execute the SQL statement
Where we used to create the connection object is mysqli is not case-sensitive, here is the use of mysqli, meaning that the extension of MySQL, both in a process-oriented way can also be object-oriented way to interact with the database, The only difference is that the function (object method) is called differently.
After you create the connection object, you need to see if the connection is successful with the IF statement test Mysqli_connect_error () and the connection is unsuccessful if False is displayed
<?PHP//create an object first, creating a Connection object$db=NewMysqli ("IP address domain name", "username", "password", "Database name"));//Write SQL statements$sql= "INSERT into info values (' p003 ', ' Zhang San ', ' 1 ', ' n001 ')";//Execute SQL statement$result=$db->query ($sql);//can judge $result the $result return value of the deletion is ture or false/*if ($result) {echo "executed successfully";} else{echo "Execution failed";}*/?>
The above is about the connection MySQL database in the modified DELETE statement, relatively simple, but also relatively single,
The following is about connecting to the MySQL database in the check SELECT statement, because the final return value is a set object, in order to facilitate a clear view of the results we use Fetch_all (), Fetch_row (); Fetch_object ();
Fetch_assoc (); More common functions such as Fetch_array () are described later, and the output is in a different way
<?PHP//Creating Objects$db=NewMysqli ("," "," "," "");//method of judging whether or not to make mistakes/*if (Mysqli_connect_errtor ()) {echo "Connection failed"; Exit;} or Mysqli_connect_error () die ("Connection Failed"): "";*///Write SQL statements$sql= "SELECT * FROM Info";//Execute SQL statement returns result set object$result=$db->query ($sql);//reading data from the result set, returning an array$attr=$result->fetch_all ()//reads all data, returns an indexed two-dimensional array$attr=$result->fetch_array ()//reads the data that the current pointer points to, and returns an array that exists for the index association$attr=$result->FETCH_ASSOC ()//returns an associative array$attr=$result->fetch_row ()//returns an indexed array$attr=$result->fetch_object ()//return Object?>
PHP connection MySQL Database