One, the connection database
Database variable file: connectvars.php
| The code is as follows |
Copy Code |
<?php Server Define (' Db_host ', ' 127.0.0.1 '); User name Define (' Db_user ', ' root '); Password Define (' Db_password ', ' root '); Database Define (' db_name ', ' test '); ?> |
To connect to a database at the point of use
| The code is as follows |
Copy Code |
Require_once ' connectvars.php '; $dbc =mysqli_connect (db_host,db_user,db_password,db_name); |
Ii. to increase, delete, change and check the database
queries, modifications, deletes are written as SQL statements
| The code is as follows |
Copy Code |
$query = "SELECT * from Toyota ORDER by ID DESC"; $data save information is rich, it can be used to determine whether the operation is successful, or use it to fetch data, query record bar number $data = Mysqli_query ($dbc, $query); |
Third, determine whether the operation is successful
| The code is as follows |
Copy Code |
if ($data) { Echo ' data operation succeeded '; }else{ Echo ' data operation failed '; } |
Iv. number of records obtained from queries
| The code is as follows |
Copy Code |
$count = Mysqli_num_rows ($data); Echo $count; |
V. Cycle operations on records
Suppose a field in the record has a ' URL '
| code is as follows |
copy code |
The
| while ($row = Mysqli_fetch_array ($data)) { echo $row [' url ']; } |