mysql_connect () connection Database
mysql_select_db Selecting a Database
MYSQL_FETCH_ASSOC () Get result set
mysql_query () Execute SQL statement
Examples are as follows:
$con = @mysql_connect (' localhost ', ' root ', ' root ');//Connect to Database
mysql_select_db (' Test ', $con);//Select Database
$userInfo =mysql_query ("SELECT * from User", $con);//Create SQL statement
echo "
"; while ($row =mysql_fetch_assoc ($userInfo))//Get data for each row of the result set {echo '
"; echo "
"; echo $row [' ID '];//gets the ID in the row echo " | "; echo "
"; echo $row [' username ']; echo " | "; echo "
"; echo $row [' Password ']; echo " | "; echo "
"; } echo "
";
Mysql_free_result ($userInfo);//Release result set
Mysql_close ($con); Close the database
/*delete
$d = @mysql_connect (' localhost ', ' root ', ' root ');
mysql_select_db (' Test ', $d);
mysql_query ("Delete from user where id=1", $d);
Mysql_close ($d);
*/
/*insert
$i = @mysql_connect (' localhost ', ' root ', ' root ');
mysql_select_db (' Test ', $i);
mysql_query ("INSERT into User (Username,password) VALUES (' Ad ', ' ad ')", $i);
Mysql_close ($i);
*/
Update
$u = @mysql_connect (' localhost ', ' root ', ' root ');
mysql_select_db (' Test ', $u);
mysql_query ("Update user set Username= ' AAA ' where username= ' xx '", $u);
echo "Update user set username= ' ax ' where id=2";
Mysql_close ($u);
?>
Thank you for your support!
Can contact me for communication. Renhanlinbsl@163.com
Technorati Tags: php,mysql, additions and deletions to change
The above describes the SQL additions and deletions to php MySQL additions and deletions, including the contents of the SQL additions and deletions, I hope that the PHP tutorial interested in a friend helpful.