mysql_connect() connects to the database
mysql_select_db selects the database
mysql_fetch_assoc() gets the result set
mysql_query() executes the sql statement
Examples are as follows:
$con=@mysql_connect('localhost','root','root');//Connect to the database
mysql_select_db('test',$con);//Select the database
$userInfo=mysql_query("select * from user ",$con);//Create sql statement
echo "
";while($row=mysql_fetch_assoc($userInfo))//Get the data of each row of the result set{echo "
";" row['username'];echo "";echo "
"; echo $row['password']; echo " | ";echo "< ;/tr>";}echo "
";
mysql_free_result($userInfo);//Release the 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='00'",$u);
echo "update user set username='ax' where id=2 ";
mysql_close($u);
?>
Thank you for your support!
You can contact me for communication. Renhanlinbsl@163.com
Technorati Tags: PHP, Mysql, add, delete, modify and check
The above has introduced sql addition, deletion and modification of PHP MySql addition, deletion and modification, including the content of sql addition, deletion and modification. I hope it will be helpful to friends who are interested in PHP tutorials.