//extension class called Mysqli MySQL is the database, mysqli is the extension ID address of the local network server address localhost if you want to link someone else's input to his server ID address. Root represents the database name,//posswd the password//database port number on behalf of the database The default is 3306//build a connection, build a Connection object$db=NewMysqli ("localhost", "root", "123", "MyDB");//Judging if there is an errorif(Mysqli_connect_error()){ Echo"Connection Failed! "; Exit;}//if the abbreviation is wrongMysqli_connect_error()? die("Connection Failed"): "";//Write SQL statements$sql= "SELECT * FROM Info"; //executes the SQL statement, returns the result set object Query method, and invokes the value returned by the $SQ1$reslut=$db->query ($sql);//reading data from the result set, returning an array$attr=$reslut->fetch_all ();//reads all data, returns an indexed two-dimensional arrayVar_dump($attr);//output, the same as the following var_dump (name); output$attr=$reslut->fetch_array ();//reads the first piece of data at a time. Reads the data that the current pointer points to, and returns an array that exists for the index association$attr=$reslut->fetch_array ();//Execute the second data again$attr=$reslut->fetch_assoc ();//returns an associative array$attr=$reslut->fetch_row ();//returns an indexed array$attr=$reslut->fetch_object ();//return Object$arr=Array();//arr Empty Container while($attr=$reslut->fetch_row ())//first Use the return index array method with the while loop, read out all the content, to attr this container name, each execution once out of a piece of data, hand over the curly braces below,{ Array_push($arr,$attr);}Var_dump($arr);//the output takes all the data and returns the two-dimensional array of indexes.
//Connecting Objects$db=NewMysqli ("localhost", "root", "123", "MyDB");//Write SQL statement//$SP 1 = "Delete from Inro where code= ' Poo2 '";//delete inro table code joins p002 this row of data$sql= "INSERT into info values (' p003 ', ' Zhang San ', ' 1 ', ' n001 ', ' 1990-2-3 ')";//This is an increase in the data of the formula, the database already has this data, is not added to, so the following if judgment must be wrong!//Execute SQL statement$result=$db->query ($sql);//Var_dump ($result); Output to see if it is deleted! if($result)//Judging{ Echo"Successful Execution!" ";}Else{ Echo"Execution failed!" ";}////////////////$result->fetch_row (); There is no formula to query, if you read it, it must be wrong//call to a member function Fetch_row () on a non~ Object in this error sentence to remember, we will often encounter!!!! First look at the SQL statement, there must be errors, either missing a symbol, or write a typo.
PHP link mysql, query database content, delete database content ... Remember link formula!!!