<?php
@ $con = mysql_connect (' localhost ', ' zsg ', ' 123456 ');
if (! $con) {
Die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ("my_db", $con);
Create a database
/* IF (mysql_query ("CREATE Database my_db", $con)) {
echo "Database created";
}else{
echo "Error Creating Database:". Mysql_error ();
} */
Creating a data Table CREATE table
The primary key field is always indexed, there is no exception to this rule, and you must index the primary key field. This allows the database engine to quickly locate the rows that are given the converted values and to add a not NULL setting for the primary key.
/* mysql_select_db ("my_db", $con);
$sql = "CREATE TABLE Persons (
Id Int (one) primary key auto_increment,
Firstname varchar (15),
Lastname varchar (15),
Age Int (11)
)";
if (mysql_query ($sql, $con)) {
echo "TABLE Persons created successfully";
} */
Inserting a new record into the database
/* $query = mysql_query ("INSERT into Persons (firstname,lastname,age) VALUES (' Zhang San ', ' John Doe ', ' 5 ')");
if ($query) {
echo "successfully inserted data";
} */
Querying data into a database, outputting it in tabular form
//
Handling of result
Where to specify a condition query
Order by sort
$result = mysql_query ("SELECT * from Persons ORDER by age ASC");
Var_dump ($result);
Echo ' <center><table border= ' "width=" 300px "height=" 200px "style=" text-align:center; Background-color:yellow; " > ';
echo "<tr><th>Firstname</th><th>Lastname</th><th>Age</th></tr>" ;
while ($row = Mysql_fetch_array ($result)) {
echo "<tr>";
echo "<td>". $row [' Firstname ']. " </td> ";
echo "<td>". $row [' Lastname ']. " </td> ";
echo "<td>". $row [' age ']. " </td> ";
echo "</tr>";
}
Echo ' </table></center> ';
To update a database
/* $sql = mysql_query ("update Persons set age = '" where Firstname = ' Zhang San ' and Lastname = ' John Doe ' ");
if ($sql) {
echo "successfully updated data";
} */
Mysql_close ($con);
Internet Information Server (IIS) Internet Information Services
Database simple additions and deletions to review