Some simple operations of PHP and Mysql
Paste the code first
The code is as follows:
Database related
$con = mysql_connect("localhost","root","root"); //Link database
if(!$con){
die('Connection failed!' . mysql_error()); //Determine whether it is successful
}
/* if(mysql_query("CREATE DATABASE testdb",$con)){ //Query or send commands through mysql_query
echo "Create testdb successfully";
}
else{
echo "Reason for failure:" . mysql_error(); //Determine whether the creation is successful
}
*/
mysql_select_db("testdb",$con); //Select the database you just created
$sql = "CREATE TABLE Persons
(personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
FirstName varchar(15),
LastName varchar(15),
Age int)
"; //Mysql statement to create table
mysql_query($sql,$con); //Execute sql statement
mysql_close($con); //Close the mysql connection
?>
The key content is
1. Link database
2. Create table
3. Enrich the content of the table according to needs
The above is the entire content of this article, I hope you guys will like it.
http://www.bkjia.com/PHPjc/961083.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/961083.htmlTechArticleSome simple operations of PHP and Mysql. First paste the code as follows: html head title database related/title /head body ?php $con = mysql_connect(localhost,root,root); //Link database if(...