Some simple php and Mysql operations, phpmysql_PHP tutorial

Source: Internet
Author: User
Some simple operations of php and Mysql, phpmysql. Some simple operations of php and Mysql, phpmysql first paste code to copy the code as follows: htmlheadtitle database related titleheadbodyphp $ conmysql_connect (localhost, root, php and Mysql some simple operations, phpmysql

Post code first

The code is as follows:




Database problems


<? Php
$ Con = mysql_connect ("localhost", "root", "root"); // link to the database
If (! $ Con ){
Die ('connection failed! '. Mysql_error (); // determines whether the request is successful.
}
/* If (mysql_query ("create database testdb", $ con) {// query or send a command through mysql_query
Echo "testdb created ";
}
Else {
Echo "cause of failure:". mysql_error (); // Determine whether the creation is successful
}
*/
Mysql_select_db ("testdb", $ con); // select the link to the created database
$ SQL = "CREATE TABLE Persons
(PersonID int not null AUTO_INCREMENT,
Primary key (personID ),
FirstName varchar (15 ),
LastName varchar (15 ),
Age int)
"; // Create a table using a Mysql statement
Mysql_query ($ SQL, $ con); // execute an SQL statement

Mysql_close ($ con); // Close the mysql connection
?>


The key content is

1. connect to the database

2. create a table

3. enrich the table content as needed

The above is all the content of this article. I hope my friends will like it.

The following code is pasted first: html head title database/title/head body php $ con = mysql_connect ("localhost", "root ","...

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.