Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
48 views

Q.1 Attempt ANY ONE of The Following (1000 Words) : A. Describe Get and Post Methods of PHP Form With Example

The document describes various data types supported in MySQL. It discusses numeric data types like INT, FLOAT, DECIMAL etc. It also covers date and time data types like DATE, TIME, DATETIME etc. Additionally, it explains string data types like CHAR, VARCHAR, TEXT and BLOB data types to store binary data. Finally, it mentions spatial data types to store geographical values and JSON data type introduced in MySQL version 5.7.8.

Uploaded by

Vijay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Q.1 Attempt ANY ONE of The Following (1000 Words) : A. Describe Get and Post Methods of PHP Form With Example

The document describes various data types supported in MySQL. It discusses numeric data types like INT, FLOAT, DECIMAL etc. It also covers date and time data types like DATE, TIME, DATETIME etc. Additionally, it explains string data types like CHAR, VARCHAR, TEXT and BLOB data types to store binary data. Finally, it mentions spatial data types to store geographical values and JSON data type introduced in MySQL version 5.7.8.

Uploaded by

Vijay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Web_Programming

Q.1 Attempt ANY ONE of the Following (1000 Words)


A. Describe Get and Post methods of PHP form with example.
Answer :
There are two ways the browser client can send information to the web server.

 The GET Method


 The POST Method
Before the browser sends the information, it encodes it using a scheme called URL
encoding. In this scheme, name/value pairs are joined with equal signs and different pairs
are separated by the ampersand.
Spaces are removed and replaced with the + character and any other nonalphanumeric
characters are replaced with a hexadecimal values. After the information is encoded it is
sent to the server.

The GET Method

The GET method sends the encoded user information appended to the page request. The
page and the encoded information are separated by the ? character.
 The GET method produces a long string that appears in your server logs, in the
browser's Location: box.
 The GET method is restricted to send upto 1024 characters only.
 Never use GET method if you have password or other sensitive information to be
sent to the server.
 GET can't be used to send binary data, like images or word documents, to the
server.
 The data sent by GET method can be accessed using QUERY_STRING environment
variable.
 The PHP provides $_GET associative array to access all the sent information using
GET method.
example by putting the source code in test.php script.

<?php
if( $_GET["name"] || $_GET["age"] ) {
echo "Welcome ". $_GET['name']. "<br />";
echo "You are ". $_GET['age']. " years old.";

exit();
}
?>
<html>
<body>

<form action = "<?php $_PHP_SELF ?>" method = "GET">


Name: <input type = "text" name = "name" />
Age: <input type = "text" name = "age" />
<input type = "submit" />
</form>

</body>
</html>

It will produce the following result −

The POST Method

The POST method transfers information via HTTP headers. The information is encoded as
described in case of GET method and put into a header called QUERY_STRING.
 The POST method does not have any restriction on data size to be sent.
 The POST method can be used to send ASCII as well as binary data.
 The data sent by POST method goes through HTTP header so security depends on
HTTP protocol. By using Secure HTTP you can make sure that your information is
secure.
 The PHP provides $_POST associative array to access all the sent information using
POST method.
 example by putting the source code in test.php script.
 <?php
 if( $_POST["name"] || $_POST["age"] ) {
 if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) {
 die ("invalid name and name should be alpha");
 }
 echo "Welcome ". $_POST['name']. "<br />";
 echo "You are ". $_POST['age']. " years old.";

 exit();
 }
 ?>
 <html>
 <body>

 <form action = "<?php $_PHP_SELF ?>" method = "POST">
 Name: <input type = "text" name = "name" />
 Age: <input type = "text" name = "age" />
 <input type = "submit" />
 </form>

 </body>
 </html>
 It will produce the following result −

Q.2 Attempt ANY TWO of the Following (800 Words)

Q.A Describe call by value and call by reference concept in PHP with example.

Answer :

Call by Value method

Call by value method copies the value of an argument into the formal parameter of that
function. Therefore, changes made to the parameter of the main function do not affect the
argument.
In this parameter passing method, values of actual parameters are copied to function's
formal parameters, and the parameters are stored in different memory locations. So any
changes made inside functions are not reflected in actual parameters of the caller.

 In Call by value method original value is not modified whereas, in Call by reference
method, the original value is modified.
 In Call by value, a copy of the variable is passed whereas in Call by reference, a
variable itself is passed.
 In Call by value, actual and formal arguments will be created in different memory
locations whereas in Call by reference, actual and formal arguments will be created
in the same memory location.
 Call by value is the default method in programming languages like C++, PHP, Visual
Basic NET, and C# whereas Call by reference is supported only Java language.
 Call by Value, variables are passed using a straightforward method whereas Call by
Reference, pointers are required to store the address of variables.

Advantages of using Call by value method

 The method doesn't change the original variable, so it is preserving data.


 Whenever a function is called it, never affect the actual contents of the actual
arguments.
 Value of actual arguments passed to the formal arguments, so any changes made in
the formal argument does not affect the real cases.
Example of a Call by Value method

void main() {
int a = 10,
void increment(int);
Cout << "before function calling" << a;
increment(a);
Cout << "after function calling" << a;
getch();

void increment(int x) {
int x = x + 1;
Cout << "value is" << x;
}

Output:

before function calling 10


value is 11
after function calling 1-0

Call by Reference method

Call by reference method copies the address of an argument into the formal parameter. In
this method, the address is used to access the actual argument used in the function call. It
means that changes made in the parameter alter the passing argument.In this method, the
memory allocation is the same as the actual parameters. All the operation in the function
are performed on the value stored at the address of the actual parameter, and the modified
value will be stored at the same address.

Advantages of using Call by reference method

 The function can change the value of the argument, which is quite useful.
 It does not create duplicate data for holding only one value which helps you to save
memory space.
 In this method, there is no copy of the argument made. Therefore it is processed
very fast.
 Helps you to avoid changes done by mistake
 A person reading the code never knows that the value can be modified in the
function.
Example of a Call by Reference method

Public static void(string args[]) {


int a = 10;
System.out.println("Before call Value of a = ", a);
Void increment();
System.out.println("After call Value of a = ", a);
}

Void increment(int x) {
int x = x + 1;
}

Output:

Before call Value of a =10


After call Value of a =11
Q. 2

C. Explain in detail all MySQL Data Types.

Answer :

A Data Type specifies a particular type of data, like integer, floating points, Boolean, etc. It
also identifies the possible values for that type, the operations that can be performed on
that type, and the way the values of that type are stored. In MySQL, each database table has
many columns and contains specific data typesfor each column. We can determine the data
type in MySQLwith the following characteristics:
o The type of values (fixed or variable) it represents.
o The storage space it takes is based on whether the values are a fixed-length or variable
length.
o Its values can be indexed or not.
o How MySQLperforms a comparison of values of a particular data type.
MySQLsupports a lot number of SQLstandard data types in various categories. It uses many
different data types that can be broken into the following categories: numeric, date and
time, string types, spatial types, and JSON data types

Numeric Data Type


MySQLhas all essential SQLnumeric data types. These data types can include the exact
numeric data types (For example, integer, decimal, numeric, etc.), as well as the
approximate numeric data types (For example, float, real, and double precision). It also
supports BIT datatype to store bit values. In MySQL, numeric data types are categories into
two types, either signed or unsigned except for bit data type. The following table contains
all numeric data types that support in MySQL:

Data Type Syntax


TINYINT
SMALLINT
MEDIUMINT
INT
BIGINT
FLOAT(m,d)
DOUBLE(m,d)
DECIMAL(m,d)
BIT(m)
BOOL
BOOLEAN

Date and Time Data Type:


This data type is used to represent temporal values such as date, time, datetime,
timestamp, and year. Each temporal type contains values, including zero. When we insert
the invalid value, MySQLcannot represent it, and then zero value is used. The following table
illustrates all date and time data types that support in MySQL:

YEAR[(2|4)]
DATE
TIME
DATETIME
TIMESTAMP(m)

String Data Types:


The string data type is used to hold plain text and binary data, for example, files,
images, etc. MySQLcan perform searching and comparison of string value based on
the pattern matching such as LIKE operator, Regular Expressions, etc.
The following table illustrates all string data types that support in MySQL

CHAR(size)
VARCHAR(size)
TINYTEXT(size)
TEXT(size)
MEDIUMTEXT(size)
LONGTEXT(size)
BINARY(size)
VARBINARY(size)
ENUM
SET

Binary Large Object Data Types (BLOB):


BLOB in MySQL is a data type that can hold a variable amount of data. They are categories
into four different types based on the maximum length of values can hold. The following
table shows all Binary Large Object data types that support in MySQL:

TINYBLOB
BLOB(size)
MEDIUMBLOB
LONGBLOB

Spatial Data Types


It is a special kind of data type which is used to hold various geometrical and geographical
values. It corresponds to OpenGIS classes. The following table shows all spatial types that
support in MySQL:

GEOMETRY
POINT
POLYGON
LINESTRING
GEOMETRYCOLLECTION
MULTILINESTRING
MULTIPOINT
MULTIPOLYGON

JSON Data Type


MySQL provides support for native JSON data type from the version v5.7.8. This
data type allows us to store and access the JSON document quickly and efficiently.
The JSON data type has the following advantages over storing JSON-format
strings in a string column:
1. It provides automatic validation of JSON documents. If we stored invalid
documents in JSON columns, it would produce an error.
2. It provides an optimal storage format.
Q3. Write Short Notes on (ANY TWO)

A. PHP function arguments

Answer:

PHP Function Arguments

Information can be passed to functions through arguments. An argument is just like a


variable.

Arguments are specified after the function name, inside the parentheses. You can add as
many arguments as you want, just separate them with a comma.

The following example has a function with one argument ($fname). When the familyName()
function is called, we also pass along a name (e.g. Jani), and the name is used inside the
function, which outputs several different first names, but an equal last name:

<?php
function familyName($fname) {
  echo "$fname Refsnes.<br>";
}

familyName("Jani");
familyName("Hege");
familyName("Stale");
familyName("Kai Jim");
familyName("Borge");
?>

OutPut

Jani Refsnes.
Hege Refsnes.
Stale Refsnes.
Kai Jim Refsnes.
Borge Refsnes.
Q3.

C . Cookie in PHP

Answer :

A cookie is a small file that the server embeds on the user's computer. Each time
the same computer requests a page with a browser, it will send the cookie too. With
PHP, you can both create and retrieve cookie values.
There are three steps involved in identifying returning users -
• Server script sends a set of cookies to the browser. For example name, age,
or identification number etc.
• Browser stores this information on local machine for future use.
• When next time browser sends any request to web server then it sends those
cookies information to the server and server uses that information to
identify the user

Acookie is created with the setcookie() function.


Syntax
setcookie(name, value, expire, path, domain, security);
Where,
Name: It is used to set the name of the cookie.
Value: It is used to set the value of the cookie.
Expire: It is used to set the expiry timestamp of the cookie after which the cookie
can’t be accessed.
Path: It is used to specify the path on the server for which the cookie will be
available.
Domain: It is used to specify the domain for which the cookie is available.
Security: It is used to indicate that the cookie should be sent only if a secure
HTTPS connection exists

The following example creates a cookie named "user" with the value "John Doe".
The cookie will expire after 30 days (86400 * 30). The "/" means that the cookie is
available in entire website (otherwise, select the directory you prefer).
We then retrieve the value of the cookie "user" (using the global variable
$_COOKIE). We also use the isset() function to find out if the cookie is set:

setcookie() function
<?php
$cookie_name = "user";
$cookie_value = "Raj";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1
day
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
</body>
</html>
The setcookie() function must appear BEFORE the <html> tag. The value of the
cookie is automatically URLencoded when sending the cookie, and automatically
decoded when received (to prevent URLencoding, use setrawcookie() instead).

Output:
Cookie 'user' is set!
Value is: Raj

You might also like