Adding Data to the Database


In the previous chunk, we created a database named produce in MySQL and added a table named fruit to hold data about various fruits. In this chunk, we'll add the data you see in Table 8-3 to the fruit database table.

Table 8-3. Fruit data

Name

Number

apples

1020

oranges

3329

bananas

8582

pears

235


To enter this data in the fruit table, continue the MySQL session started in the previous chunk, or start a new one in a command window:

 %mysql -u root Welcome to the MySQL monitor.  Commands end with ; or \g. 

Switch to the produce database and use INSERT to load the data into the fruit table:

 mysql> USE produce Database changed mysql> INSERT INTO fruit VALUES ('apples', '1020'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO fruit VALUES ('oranges', '3329'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO fruit VALUES ('bananas', '8582'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO fruit VALUES ('pears', '235'); Query OK, 1 row affected (0.00 sec) 

That's it; you can list the data in this table with SELECT to confirm that everything's as it should be, and then end the session with quit, completing our new database table:

 mysql> SELECT * FROM fruit; +---------+--------+ | name    | number | +---------+--------+ | apples  | 1020   | | oranges | 3329   | | bananas | 8582   | | pears   | 235    | +---------+--------+ 4 rows in set (0.00 sec) mysql>quit 



    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net