PHP and MySQL for some simple operation

Source: Internet
Author: User

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.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.