PHP and MySQL for some simple operation

Source: Internet
Author: User
Tags php and php and mysql create database

Post Code First

The code is as follows:
<title> Database Related </title>
<body>
<?php
$con = mysql_connect ("localhost", "root", "root"); Link Database
if (! $con) {
Die (' Connection failed! ' . Mysql_error ()); To judge whether or not to succeed
}
/* IF (mysql_query ("CREATE DATABASE testdb", $con)) {//mysql_query query or Send command
echo "Create TestDB success";
}
else{
echo "Reason for failure:". Mysql_error (); To determine whether a success was created
}
*/
mysql_select_db ("TestDB", $con); Select the database that the link 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 Creation Table
mysql_query ($sql, $con); Execute SQL statement

Mysql_close ($con); Close MySQL Connection
?>
</body>

The key element is

1, linked to the database

2. Create a table

3, according to the needs of the table content to enrich

The above is the entire content of this article, I hope that the small partners can enjoy.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.