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//first create an object, that is, make a Connection object $db=new mysqli ("IP address domain name", "User name", "Password", "database Name");//write SQL statement $sql= "INSERT into info values (' P003 ', ' Zhang San ', ' 1 ', ' n001 ');//execute the SQL statement $result= $db->query ($sql);//You can tell $result the $result return value 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//Create object $db=new mysqli ("," "," "," ");//The method of judging whether the error is/*if (Mysqli_connect_errtor ()) { echo" Connection failed "; Exit;} or Mysqli_connect_error () die ("Connection Failed"): ""; *///write SQL statement $sql= "SELECT * from Info";//Execute SQL statement return result set object $result= $db->query ($sql);//reads data from the result set, returns the array $attr= $result->fetch_all ()//reads all data, returns the index two-dimensional array $attr= $result->fetch_array ()// Reads the data pointed to by the current pointer, returns an array $attr= the index association exists $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 and delete and change