Sabtu, 22 Juni 2013

How to Create a Table in PHP

One of the benefits of using the server-side language PHP is that it contains built-in tools for interacting with your MySQL databases. If you have a MySQL database set up, you can create and manage tables inside the database using PHP code alone to create connections to the database and to send it queries. Creating a simple table inside a database using PHP is a straightforward process once you know the code to do it.

Instructions

    1

    Create a MySQL database on your server. Log in to your website's control panel, search for the "Databases" or "MySQL" section, and select the "Create new database" option. You'll need to provide a database name, a username (which is sometimes the same as the database name) and a password. Keep this information handy.

    2

    Open a new PHP file. To create a table, you need to make a connection to the database and then send it a query filled with your instructions on creating the table. To make a connection, first house all the connection details inside a variable, traditionally called "$conn," and use the "mysql_select_db" command to select the specific database:
    $conn = mysql_connect("servername", "username", "password");
    mysql_select_db("databasename");
    Replace "username," "password," and "databasename" with your database information. Usually, your server name will be "localhost," but if that doesn't work you'll either need to poke around your site's control panel for the information or ask your hosting provider.

    3

    Create a variable to house your SQL query, and create the table using the CREATE TABLE query. Here is a variable containing the query to a very simple table called "books":
    $sql = "
    CREATE TABLE books (
    idnumber INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR (75),
    author VARCHAR (50),
    ); ";
    This table has only three columns: "idnumber," "name" and "author." The mess of code after "idnumber" is simply declaring that column as the table's "primary key," which ensures that each row on your table will have a unique behind-the-scenes ID number. The "name" and "author" columns are both given the field type "VARCHAR," which stands for "various characters" and is the basic type for a simple text field. The number afterward is the maximum amount of characters each field can be. Keep these numbers as small as you think you can get away with to save space.

    4

    Add a row to the table using the INSERT query. Since it's a separate query, you'll have to create a new variable for it:
    $sql2 = "
    INSERT INTO books VALUES
    (null, 'Oliver Twist', 'Charles Dickens');
    ";
    The "null" simply lets the MySQL database know that that's where the primary key (the unique ID number) should go. MySQL will assign the keys automatically. The next two fields fill in the "name" and "author" columns, respectively.

    5

    Put everything together with the mysql_query command. You'll have to run it twice to execute both queries:
    mysql_query($sql, $conn);
    mysql_query($sql2, $conn);

    6

    Save your PHP file (and make sure you house everything in the file inside the "" PHP tags. When run, it should create the "books" table in your database. Put all together, the code should look like this:
    $conn = mysql_connect("localhost," "demandstudios," "demandstudios") or die(mysql_error());
    mysql_select_db("test");
    $sql = "
    CREATE TABLE books (
    idnumber INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR (75),
    author VARCHAR (50)
    ); ";
    $sql2 = "
    INSERT INTO books VALUES
    (null, 'Oliver Twist', 'Charles Dickens');
    ";
    mysql_query($sql, $conn) or die(mysql_error());
    mysql_query($sql2, $conn) or die(mysql_error());
    ?>



  • Create database, table and managing MySQL database using phpMyAdmin

    www.phpeasystep.com/mysqlview.php?id=2

    phpMyAdmin is a tool for managing MySQL database and free of charge, it's a web base tool. This tutorial you'll learn how to create database, create table include ...


  • PHP MySQL - Create Table

    www.createafreewebsite.net/phpmysql/create_table.html

    PHP MySQL How to create a table in your database. ... We're Being Sued by gettyimages. I was wondering who would put the final nail in our coffin.


  • PHP Create Database and Tables - W3Schools Online Web Tutorials

    www.w3schools.com/PHP/php_mysql_create.asp

    Create a Database. The CREATE DATABASE statement is used to create a database table in MySQL. We must add the CREATE DATABASE statement to the mysqli_query() function ...


  • PHP MySQL - PHP MySQL Tutorial - Create Table

    php.about.com/od/phpwithmysql/ss/mysql_php_4.htm

    Run SQL queries from a PHP script, Connect to MySQL from PHP and create tables as shown in our PHP MySQL Tutorial


  • MySQL Tutorial - Create Table - Tizag Tutorials

    www.tizag.com/mysqlTutorial/mysqltables.php

    Learn how to create a MySQL table with Tizag.com's MySQL Table lesson.


  • How to Create a Table in PHP eHow

    www.ehow.com/how_5126991_create-table-php.html

    One of the benefits of using the server-side language PHP is that it contains built-in tools for interacting with your MySQL databases. If you have a MySQL database ...


  • How to create a MySQL table - Web Hosting Services, VPS Servers ...

    www.ntchosting.com/mysql/create-table.html

    In our example we will use a PHP script to create a table 'moredata' which will contain info about 'gender', 'age' and 'country' in the corresponding fields.


  • How to Create a Table Using PHP eHow

    www.ehow.com/how_8717667_create-table-using-php.html

    Using a combination of PHP and MySQL, you can develop Web applications that take information from users, store it in a database and then output the data at a later ...


  • Create a MySQL Table with PHP GIDBlog

    www.gidblog.com/2001/04/create-a-mysql-table-with-php

    One thing I often asked myself, when I first started programming in PHP, was How do I create a MySQL database table with PHP? Of course, I have come a long way since ...


  • How To Use PHP Tables Instead of Frames

    www.garnetchaney.com/how_to_use_tables_instead_of_frames.shtml

    Replace Frames with PHP Tables - Creating the PHP script - index.php. Author: roddefig. How it all Works.


  • PHP How to Create Table - JSP Tutorials,EJB Tutorial,JDBC ...

    roseindia.net/tutorial/php/phpdatabase/PHP-Create-Table.html

    PHP Create Table - This PHP tutorial serries, we are going to learn how to create tables in PHP programming language. Learn how to make table using php. The sql ...


  • how to create dynamic table in php?: php, table, dynamic, create

    www.experts-exchange.com/.../PHP/PHP_Databases/Q_23054820.html

    I have link field in database which currently hold 4 link. I want to display that data in php page as tabular form . Link 1 ...


  • How to create Database & Tables using PhpMyAdmin

    www.smartwebby.com/PHP/database_table_create.asp

    Create a Database and table using PhpMyAdmin - In this tutorial you will learn about creating a new database and new table using PHPMyAdmin


  • Create database and table with PHP + MySQL - YouTube

    www.youtube.com/watch?v=HJ0-jW8tFu8By Guto Ferreira 10 min 86,343 views Added 07/12/2007

    [+]see more http://www.revista-php.net On this video you will learn how to create databases and tables with MySQL and PHP


  • Create table with PHP and populate from MySQL - Stack Overflow

    stackoverflow.com/questions/3050558Last updated: 16/06/2010 5 posts First post: 16/06/2010

    Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.


  • PHP-Nuke

    www.phpnuke.org/modules.php?name=PHP-Nuke_HOWTO&page=html-create...

    How to create a table in HTML. The important HTML tags for tables ... if we wanted to insert the text "PHP-Nuke" in the first line of the left column of the above ...


  • PHP MySQL Tutorial: Create a Database and Table in phpMyAdmin -HD ...

    www.youtube.com/watch?v=nBz2lG_jm-ABy RiverCityGraphix 11 min 247,039 views Added 21/08/2010

    In this tutorial, you will learn how to create a database and table within phpMyAdmin. Be sure to SUBSCRIBE because there will be a new tutorial every week ...


  • MySQL Tutorial: Create SQL Tables - Learn PHP - PHP Tutorials ...

    php.about.com/od/learnmysql/ss/create_tables.htm

    One of the easiest way to create a table is through phpMyAdmin, which is available on most hosts that offer MySQL databases (ask your host for a link).


  • How to Create a database and table in phpMyAdmin PHP

    php.wonderhowto.com/how-to/create-database-and-table-phpmyadmin-393572

    In this clip, you'll learn how to go about creating databases and tables from within the phpMyAdmin tool. Whether you're new to the PHP: Hypertext Preprocessor ...


  • MySQL PHP Web Database Tutorial: Create Database - web.blazonry

    blazonry.com/scripting/linksdb/create_table.php

    web blazonry Learn web technologies PHP, MySQL, java, javascript, style sheets, server-side scripting including examples, tutorials, source code and recomended books ...

Tidak ada komentar:

Posting Komentar