PHP Create DATABASE data table

Source: Internet
Author: User
Tags php create database

PHP Create DATABASE data table

<?php

$con = mysql_connect (' localhost ', ' root ', ' root ');

/************************ creating tables in the database *************************/

if (! $con) {

Die (' Connection Database error: '. mysql_error ());

}

$database = "My_db_name";

$sqlDatabase = ' Create database '. $database;

if (mysql_query ($sqlDatabase, $con))

{

echo "Congratulations, database". $database. " Created successfully! ";

}

Else

{

echo "CREATE database error, error number:". Mysql_errno (). "Error Reason:". mysql_error ();

}

/******************************end***************************************/

/************************ creating tables in the database *************************/

mysql_select_db ("My_db_name", $con);

?

$sqlTable = "CREATE Table My_table_name (

ID int unsigned NOT NULL Auto_increment primary key,

A varchar (20),

b varchar (2),

C varchar (1)) ";

?

if (mysql_query ($sqlTable))

{

echo "Congratulations, data sheet creation succeeded!";

}

Else

{

echo "Create data table error, error number:". Mysql_errno (). "Error Reason:". mysql_error ();

}

/******************************end***************************************/

?

/************************* writing data to a table *********************************/

Guarantee has been implemented:

mysql_connect ("localhost", "username", "passcode");//Connect MySQL

mysql_select_db ("db_name");//Select Database

$sql = "INSERT into My_table_name (A, B) values (' 123 ', ' 45 ')"; '--' can be a variable in single quotation marks

if (mysql_query ($sql))//INSERT data through SQL statement

{

echo "Congratulations, the table writes the data successfully!";

}

/******************************end***************************************/

?

Mysql_close ();

?>

PHP Create DATABASE data table

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.