Server Side Programming: by Dr. Babaousmail Hassen Lecturer at Binjiang College of NUIST
Server Side Programming: by Dr. Babaousmail Hassen Lecturer at Binjiang College of NUIST
Server Side Programming: by Dr. Babaousmail Hassen Lecturer at Binjiang College of NUIST
1
GRANT & REVOKE Command
The GRANT command is used to give privileges to a user. The opposite of GRANT
is REVOKE. It is used to take privileges away from a user.
2
Examples Using GRANT and
REVOKE
To set up an administrator, you can type:
This grants all privileges on all databases to a user called Fred with the password
mnb123, and allows him to pass on those privileges.
If you don’t want this user in your system, so go ahead and revoke him:
3
To set up a regular user with no privileges:
And later, when she doesn’t need to use the database any more, we can revoke her
privileges:
mysql> revoke all
-> on books.*
-> from sally;
4
Example
5
Read & Understand Following Table Exercises in MySQL
And then Note in your Notebook.
1. Write a SQL statement to create Here is the structure of the table:
a simple table countries including
columns country_id,country_name mysql> DESC countries;
and region_id. +--------------+---------------+------+-----+---------
+-------+
Sample Solution: | Field | Type | Null | Key | Default |
CREATE TABLE countries( Extra |
COUNTRY_ID varchar(2), +--------------+---------------+------+-----+---------
COUNTRY_NAME varchar(40), +-------+
REGION_ID decimal(10,0) | COUNTRY_ID | varchar(2) | YES | |
); NULL | |
| COUNTRY_NAME | varchar(40) | YES | |
The CHAR and VARCHAR types are similar, NULL | |
but differ in in maximum length. | REGION_ID | decimal(10,0) | YES | |
The CHAR and VARCHAR types are declared NULL | |
with a length that indicates the maximum +--------------+---------------+------+-----+---------
number of characters you want to store. For +-------+
example, CHAR(30) can hold up to 30 3 rows in set (0.01 sec)
characters.
The length of a CHAR column is fixed and The length of a VARCHAR column can be a value
can be any value from 0 to 255. from 0 to 65,535. 6
Error
If you will run the previous commands in MySQL, you may get an
error as
NO DATABASE Selected
7
Here is the structure of the table:
8
Here is the structure of the table:
9
4. Write a SQL statement to create a table
Here is the structure of the table:
named countries including columns
country_id, country_name and region_id
mysql> DESC countries;
and make sure that no countries except Italy,
+--------------+---------------+------+-----+-----
India and China will be entered in the table.
----+-------+
| Field | Type | Null | Key | Default
Sample Solution:
| Extra |
+--------------+---------------+------+-----+-----
CREATE TABLE IF NOT EXISTS countries (
----+-------+
COUNTRY_ID varchar(2),
| COUNTRY_ID | varchar(2) | YES | |
COUNTRY_NAME varchar(40)
NULL | |
CHECK(COUNTRY_NAME
| COUNTRY_NAME | varchar(40) | YES |
IN('Italy','India','China')) ,
| NULL | |
REGION_ID decimal(10,0)
| REGION_ID | decimal(10,0) | YES | |
);
NULL | |
+--------------+---------------+------+-----+-----
Let execute the above code in MySQL
----+-------+
command prompt
3 rows in set (0.01 sec)
10
5. Write a SQL statement to create a
table named countries including
columns country_id,country_name and
Here is the structure of the table:
region_id and make sure that no mysql> DESC countries;
duplicate data against column +--------------+---------------+------+-----+---
country_id will be allowed at the time of ------+-------+
insertion. | Field | Type | Null | Key |
Default | Extra |
Sample Solution: +--------------+---------------+------+-----+---
------+-------+
| COUNTRY_ID | varchar(2) | YES |
CREATE TABLE IF NOT EXISTS
| NULL | |
countries (
| COUNTRY_NAME | varchar(40) | YES
COUNTRY_ID varchar(2) NOT NULL, | | NULL | |
COUNTRY_NAME varchar(40) NOT | REGION_ID | decimal(10,0) | YES |
NULL, | NULL | |
REGION_ID decimal(10,0) NOT NULL, +--------------+---------------+------+-----+---
UNIQUE(COUNTRY_ID) ------+-------+
); 3 rows in set (0.01 sec)
12
Revision
Some Simple Questions
13
Which Command is used to
see all databases in MySQL?
14
Which command is used to
delete any database in
MySQL?
15
What is the command line to
create any database in
MySQL?
16
What is the meaning of id INT
NOT NULL
AUTO_INCREMENT
PRIMARY KEY?
17
Which command is used to see
the structure of tables in
MySQL?
18
Which command is used to see
the data of a table in MySQL?
19
Which command is used to
insert data in a table in
MySQL?
20
When we get this error “NO
DATABASE Selected “
21
What is the meaning of Grant
and Revoke Commands?
22
Your First PHP Script
Open your favorite text editor or HTML editor and create a new file called
today.php. Type this into the file:
Alert Windows users should note that, to save a file with a .php extension in
Notepad, you’ll need to select All Files as the otherwise, Notepad will
unhelpfully save the file as today.php.txt, which will fail to work.
If you are getting any problem in editing PHP scripts. There are a number of solid
text editors and Integrated Development Environments (IDEs) with rich support for
editing PHP scripts that you can download for free. Here are a few that work on
Windows, Mac OS X, and Linux:
NetBeans: http://www.netbeans.org/features/php
Aptana: http://www.aptana.com/php
Komodo Edit: http://www.activestate.com/komodo_edit
If you’re using an Apache server you installed manually, the web root directory is the
htdocs directory within your Apache installation (that is, C:\Program Files\Apache
Software Foundation\Apache2.2\htdocs on Windows
24
Alert Use encoding UTF 8 while saving the earlier file
Sometime we receive a message from the window that we cannot save the file in the
earlier directory. In that case just save the file on desktop and then cut and paste in
the previous directory
You will see the following out put if everything is correct otherwise you may get an
error message due to some mistakes during the installation.
Today’s date (according to this web server) is Sunday, September 29th 2019.
25
The web server interpret everything between delimiters, and convert it to regular
HTML code before it sends the requesting browser.
The browser is presented with the following if you will see the source of following
link:
Today’s date (according to this web server) is Wednesday, November 15th 2017.
• In the above example, we placed the date, according to the web server, into the
web page. If we had inserted the date using JavaScript, we will only be able to
display the date according to the computer on which the web browser was
running.
• Java Script can delay the display of a webpage on slower computers significantly,
as the browser must run the script before it can display the web page.
27
Another Simple Example of PHP
Script
To process the form, we need to create the script say processorder.php. Open
your text editor and create this file. Type in the following code:
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
</body>
</html>
Notice, how everything we’ve typed so far is just plain HTML. It’s now
time to add some simple PHP code to our script. 28
Embedding PHP in HTML
Under the <h2> heading in your file, add the following lines:
<?php
echo '<p>Order processed.</p>';
?>
Save the file and load it in your browser (Type the following address in
address of your browser- http://localhost/processorder.php or
http://localhost:port/processorder.php). You should see something similar
to the output shown in Figure 1.2.
29
Home Assignment-III
30