Page 238 - Open Soource Technologies 304.indd
P. 238

Unit 14: Connecting to MySQL with PHP



                                                                                                  Notes

                      The prompt changes from ‘mysql’ to ‘->’after you enter the first line of query.


            If you have begun typing in a multiple-line query and decide you don’t want to execute it, type
            ‘\c’ to clear(cancel) it.

            mysql>SELECT NOW(),
            ->USER(),

            ->\c
            mysql>



                       The  prompt  changes  back to mysql>  to  indicate  that mysql  is  ready  for  new
                      query.’c’ is always lowercase.


            14.2.4 Creating a Database

            The  first  step  in  database  management,  is  to  create  a  database.  The  following  steps  are
            demonstrated using a database sample_db:

               1.  Creating (initializing) the database.
               2.  Creating the tables within the database.

               3.  Interacting with the tables by inserting, retrieving, modifying, or deleting data.

            After connection to the server issue the following query to create database by name sample_db

            mysql>CREATE DATABASE sample_db;
            Now, a database by name sample_db is created, but still not in use. You need to issue USE
            <database-name> command to perform any operations on the database. SELECT DATABASE()
            command can be used to view the database in use as shown below:

            mysql> SELECT DATABASE();















            To make the sample_db as the current database in use, issue the command:
            mysql>USE sample_db





                                             LOVELY PROFESSIONAL UNIVERSITY                                   233
   233   234   235   236   237   238   239   240   241   242   243