Home > Backend Development > PHP Tutorial > Some simple operations with php and Mysql_PHP tutorial

Some simple operations with php and Mysql_PHP tutorial

WBOY
Release: 2016-07-13 10:05:59
Original
703 people have browsed it

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.

www.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(...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template