Connect MySQL data access in the PHP system, + + + + + data removal

Source: Internet
Author: User

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >PHP//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.?></body>

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >PHP//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 go to read, it must be wrong//call to a member function Fetch_row () on a non~object in this error statement to remember, We will often meet!!!! First look at the SQL statement, there must be errors, either missing a symbol, or write a typo. ?></body>

Connect MySQL data access in the PHP system, + + + + + data removal

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.