Difference between revisions of "Create Database and Tables"
(One intermediate revision by one user not shown) | |||
Line 2: | Line 2: | ||
{| class="wikitable" style="float:right;margin:1em;width:300px;" | {| class="wikitable" style="float:right;margin:1em;width:300px;" | ||
|- | |- | ||
− | ! [[Closing a Connection|Previous Page]] !! [[ICT-Application| Home Page]] !! [[Insert Into | + | ! [[Closing a Connection|Previous Page]] !! [[ICT-Application| Home Page]] !! [[Insert Into Statement|Next Page]] |
|- | |- | ||
|}<div style="text-align:center;font-weight:bold;padding:0.4em 1em 0.3em 1em;-moz-border-radius: 6px;background-color:#47b8b8; ">ICT Applications</div> | |}<div style="text-align:center;font-weight:bold;padding:0.4em 1em 0.3em 1em;-moz-border-radius: 6px;background-color:#47b8b8; ">ICT Applications</div> | ||
− | === Create a Database === | + | ===<font color=green> Create a Database </font> === |
The CREATE DATABASE statement is usedto create a database in MySQL. | The CREATE DATABASE statement is usedto create a database in MySQL. | ||
Line 54: | Line 54: | ||
|} | |} | ||
− | === Create a Table === | + | ===<font color=green> Create a Table </font> === |
The CREATE TABLE statement is used tocreate a table in MySQL. | The CREATE TABLE statement is used tocreate a table in MySQL. | ||
Line 149: | Line 149: | ||
{| class="wikitable" style="float:right;margin:1em;width:300px;" | {| class="wikitable" style="float:right;margin:1em;width:300px;" | ||
|- | |- | ||
− | ! [[Closing a Connection|Previous Page]] !! [[ICT-Application| Home Page]] !! [[Insert Into | + | ! [[Closing a Connection|Previous Page]] !! [[ICT-Application| Home Page]] !! [[Insert Into Statement|Next Page]] |
|- | |- | ||
|}<div style="text-align:center;font-weight:bold;padding:0.4em 1em 0.3em 1em;-moz-border-radius: 6px;background-color:#47b8b8; ">ICT Applications</div> | |}<div style="text-align:center;font-weight:bold;padding:0.4em 1em 0.3em 1em;-moz-border-radius: 6px;background-color:#47b8b8; ">ICT Applications</div> | ||
[[Category:TOPICS]] | [[Category:TOPICS]] |
Latest revision as of 12:00, 21 January 2013
Previous Page | Home Page | Next Page |
---|
Create a Database
The CREATE DATABASE statement is usedto create a database in MySQL.
Syntax
Contents |
CREATE DATABASE database_name
Example
The following example creates adatabase called "my_db":
<?php $con =mysql_connect("localhost","userid","abc123"); if (!$con) { die('Could not connect: ' .mysql_error()); } if (mysql_query("CREATE DATABASEmy_db",$con)) { echo "Database created"; } else { echo "Error creatingdatabase: " . mysql_error(); } mysql_close($con); ?> |
Create a Table
The CREATE TABLE statement is used tocreate a table in MySQL.
Syntax
CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, .... ) |
We have to add the CREATE TABLEstatement to the mysql_query() function to execute the command.
Example
The following example creates a tablenamed "Contacts", with four columns. The column names willbe "FirstName", "LastName" and "Phone":
<?php $con =mysql_connect("localhost","userid","abc123"); if (!$con) { die('Could not connect: ' .mysql_error()); } // Create table mysql_select_db("my_db",$con); $sql = "CREATE TABLE Contacts ( FirstNamevarchar(15), LastNamevarchar(15), Phoneint )";
mysql_query($sql,$con);
?>
|
Previous Page | Home Page | Next Page |
---|