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 ","...