PHP interacts with MySQL
A simple example of the code logic is: Make a connection, create a table, insert data, get the data, and display the results.
(1): Command line Build test database
(2): The following is a PHP script ( to connect, create a table, insert data, get data, and display the results)
A record has been inserted. "; /query Record $sql_2= "SELECT * from TestTable", $res _2=mysqli_query ($mysqli, $sql _2), if ($res _2) {//show number of record bars $number_of_rows = Mysqli_num_rows ($res _2);p rintf ("
Result set has%d rows.\n ", $number _of_rows);//Gets data and displays the result while ($newArray = Mysqli_fetch_array ($res _2, Mysqli_assoc)) {$ id = $newArray [' id ']; $testField = $newArray [' Testfield '];echo "
The ID is ". $id." And the text is ". $testField."
";}} else {printf ("Could not retrieve records:%s\n", Mysqli_error ($mysqli));}} else {printf ("Could not insert Record:%s\n", Mysqli_error ($mysqli));}} else {printf ("Could not create table:%s\n", Mysqli_error ($mysqli));} Mysqli_close ($MYSQLI);}
Through server access, the effect is as follows:
Go to the command line to view the database
The above describes the PHP and MySQL interaction, including aspects of the content, I hope the PHP tutorial interested in a friend to help.