MySQL Activity-Environment and Languages for Programming-Lab Task, Lecture notes of Programming Languages

Prof. Gaurav Bhatt assigned this lab task for Environment and Languages for Programming course at Institute of Company Secretaries of India - ICSI. Its main parts are: MySQL, Activity, Command, Line, Interface, Database, Password, Protected, Connection, Prompt

Typology: Lecture notes

2011/2012

Uploaded on 07/16/2012

sambandan
sambandan ๐Ÿ‡ฎ๐Ÿ‡ณ

4.7

(3)

35 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
m ys ql - h m ys ql { us e r }
where {user} should be replaced by your departmental user name ({user} indicates
which database you want to use).
If successful, you should see the following output in the terminal, and you are now
interacting with our MySQL server using its command line interface:
Wel co me to t he M yS QL mo ni to r. Co mm an ds en d wi th ; o r \g .
You r My SQ L c on ne ct io n id i s 25 35 21 4
Ser v er ve rs i on : 5. 1. 56 So u rc e dis t ri b ut i on
Cop y ri g ht (c ) 20 00 , 201 0 , O ra c le and / o r it s a f fi l ia t es . A ll ri gh t s r es e rv ed .
Thi s s o ft w ar e c o me s w it h A B SO L UT E LY NO W A RR A NT Y . T hi s i s fr e e s of tw ar e ,
and y ou a re w el co me to modify an d red is tr ib ut e it u nd er t he GP L v2 l ic en se
Typ e โ€™ h e lp ; โ€™ o r โ€™ \h โ€™ f o r h e lp . Ty pe โ€™\ c โ€™ to cl ea r t h e c u r re n t i n p ut st a te m e n t .
mys ql >
1
docsity.com
pf3
pf4

Partial preview of the text

Download MySQL Activity-Environment and Languages for Programming-Lab Task and more Lecture notes Programming Languages in PDF only on Docsity!

mysql -h mysql { user }

where {user} should be replaced by your departmental user name ({user} indicates which database you want to use).

If successful, you should see the following output in the terminal, and you are now interacting with our MySQL server using its command line interface:

Welcome to the MySQL monitor. Commands end with ; or \ g. Your MySQL connection id is 2535214 Server version : 5.1.56 Source distribution

Copyright ( c ) 2000 , 2010 , Oracle and / or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software , and you are welcome to modify and redistribute it under the GPL v2 license

Type โ€™ help ; โ€™ or โ€™\h โ€™ for help. Type โ€™\c โ€™ to clear the current input statement.

mysql >

b. By default, your database is not password protected, meaning that anyone can access it. To set a password for your database, use the following command at the MySQL prompt: set password = password ( โ€™{ password } โ€™);

where {password} should be replaced by a password chosen by yourself. Note that you must be able to remember that password. It should also not coincide with your departmental or MWS passwords. If successful, you will see the output Query OK , 0 rows affected (0.00 sec )

c. We should now test whether your password is working. First, disconnect your connec- tion to the MySQL server by using the command quit ;

You are now back at the shell command prompt and should reconnect to the MySQL server using one of the following two commands: mysql -h mysql -p { user } mysql -h mysql -u { user } -p { user }

where {user} should be replaced by your departmental user name (the option -u {user} specifies the MySQL user id that you want to use when connecting to the MySQL server, it defaults to your departmental user name). You should now be asked to enter a password: Enter password :

After entering the password that you have specified in 1b. you should be back at the MySQL prompt.

d. Let us create our first database table in MySQL using the following command at the MySQL prompt: create table meetings ( slot INT NOT NULL , name VARCHAR (50) , email VARCHAR (50) , primary key ( slot ));

e. If the command in 1d. was successful, then describe meetings ;

should produce the following output

              • -+ - - - - - - - - - - - - -+ - - - - - -+ - - - - -+ - - - - - - - - -+ - - - - - - -+ | Field | Type | Null | Key | Default | Extra |
              • -+ - - - - - - - - - - - - -+ - - - - - -+ - - - - -+ - - - - - - - - -+ - - - - - - -+ | slot | int (11) | NO | PRI | NULL | | | name | varchar (50) | YES | | NULL | | | email | varchar (50) | YES | | NULL | |
              • -+ - - - - - - - - - - - - -+ - - - - - -+ - - - - -+ - - - - - - - - -+ - - - - - - -+ 3 rows in set (0.00 sec )

f. We now want to fill the meetings table with some data

$rows = mysql_num_rows ( $result ); echo " Rows retrieved : $rows < br / > < br / >\ n "; for ( $j = 0; $j < $rows ; $j ++) { echo " Slot : " , mysql_result ( $result , $j , โ€™ slot โ€™) ," < br / >\ n "; echo " Name : " , mysql_result ( $result , $j , โ€™ name โ€™) ," < br / >\ n "; echo " Email : " , mysql_result ( $result , $j , โ€™ email โ€™) , " < br / > < br / >\ n "; } mysql_close ( $con ); ? > </ body > </ html >

Replace both occurrences of {user} with your departmental user name and replace {password} with the password you have chose for your database.

b. Save the code to a file name phpDB1.php in $HOME/public_html/. Make the file read- able for everyone by using

chmod a+r โˆผ/public_html/phpDB1.php

You should only have to do so once. File permissions should not change while you continue to edit the file. c. Execute the PHP script in the terminal using the command

php โˆผ/public_html/phpDB1.php

Check that there are no syntax errror and that the script produces the output < html > < head > </ head > < body > Include worksRows retrieved : 3 < br / > < br / > Slot : 1 < br / > Name : Michael North < br / > Email : M. North@student. liverpool. ac. uk < br / > < br / > Slot : 5 < br / > Name : Jody Land < br / > Email : J. Land@student. liverpool. ac. uk < br / > < br / > Slot : 7 < br / > Name : Trish Shelby < br / > Email : T. Shelby@student. liverpool. ac. uk < br / > < br / > </ body > </ html >

d. Open a web browser and access the url

http://www.csc.liv.ac.uk/โˆผ{user}/phpDB1.php

where {user} should be replaced by your departmental user name. Make sure that the web page you are shown corresponds to the HTML code you have seen in 2c. e. It would be nice if the database data would be presented in the form of a HTML table, similar to that shown in 1f..