Submit the form by clicking
thise/div>
19
20
1 ”;
Becho “Your email :”. $_POSTI'e'l. “
”;
4echo “Your mobile :”. $_POSTI'm'). “
”;
5 echo “Your Adds :” .$_POST{‘reply’};
62>LP. University-BCA}-Akash Books 2017-11
its standard channel. Also it is used to perform gray it
i phical stuffs of a website. All the
ee re are equipped with the inbuilt PHP [Link] is an open source
sane oe ereen Said that it has very less support online and offline, But, PHP
< al together diferent language nae is being developed by group of programmers,
3 of avail iT
" 4 ees Wailable support for PHP, which mostly comes from
After installing and configuring the PHP, the web When PHP is installed, the Web
code that is embedded in HTML file with its extension, The
itself. When the i is bei
ee cea anne Processing gets over the output is being shown
Being a server side scripting language PHP can be smoothly embedded with the
HTML. For dynamic and interactive websites, PHP is an indispensible thing. This
scrip0ting language is so vast that it can be used with the JAVA script and database
such as MySQL server. The open source technology of PHP is backed with a large
community support. The benefit of PHP is “ it is not platform supported. It works
smoothly for all the operating systems including LINUX and Windows. For the core
development of PHP, a large collection of open source is available.
Web The Web. PHP * Disk = MySQL.
browser Intemet_ Server. Processor drive database
i Enter |...
URL
| Lookup
the IP
7
Fetch
pegLP. University-{BCA} Akash Books 2017-13
Download “Windows NT 4.0 Option Pack”
Ifyou don’t have Windows 98 CD with i
4 SaEAtatachen you, no problem. You can download it from
Download “Personal Web Server”
Installing Personal Web Server on Windows 98:
1, Insert your Windows 98 CD into your CD-ROM Drive.
2. Explore your CD-ROM Drive.
3. Qpen "add-ons" folder, there you will ind “pws” folder, run “[Link]” from this
4. Follow the instructions on the screen to install “Personal Web Server”
After installation of PWS, you will find a PWS icon on your desktop and most
probably a small icon of PWS in the right corner of the taskbar. Open any one of them.
Ifthe PWS is running then you will see an option “Stop PWS" or else you will see “Start
pws”.
‘To check if PWS is running, open your Internet Explorer. In the URL box enter http:/
/[Link] or http/ocalhost and press Enter. If everything is working fine, you will see
a default page generated by PWS. If you can see any page then PWS is running correctly
or else you have to restart your computer and start PWS again and continue the same
process.
Q. 2. (c) PHP and JavaScript are both programming languages that generate
dynamic results for web pages. What is the main difference and why would you
use both of them. 3.5)
Ans. PHP (PHP Hypertext Preprocessor) is a young language when compared to the
| likes of Perl and C and other largely popular languages. It was started in 1995 by Rasmus
Lerdorf initially as a simple set of Perl scripts he named ‘Personal Home Page Tools’,
later he expanded it and implemented it in C and then released it as an open source
code base for all to use (The PHP Group, 2010). Ithas since then evolved from a procedural
language to an OO language in its PHP 5 release (July 2004).14-2017 e
a. InP code willbe avaiablenny
the code can be viewed even aftek owl
deca edly wih HTML and PUP =
‘JavaScript can be combined with HTME, XML and AJAK.
iL PHP is used to produce web pages
le on the server, and gain files of
the files availal
JavaScript can import files of information available
jn the address bar of the browser: .
's PHP does not execute within a browser's window while JavaScript executes witha)
a browser's window.
6. PHP commonly uses MYSQL as a database while MYSQL is not: commonly
by JavaScript.
after
tput is interpreted:
Q.3. (a) Whatis a web
server.
vans, A web server is a computer system that
basic network protocol used. to distribute information on
can refer either to the entire system, oF specifically to the so!
supervises the HTTP requests.
The most common use of web servers is to host websites, but there are other
such as gaming, data storage, venning enterprise applications, handling email, FTP,
other web uses.
“Web servers often come as part ofa larger package, of Internet- and intranet-rel
i H sts for File Transfer Protocol (FTP )
ili ! in choosing a Web server i
lit works with the operating system and other seve its ability to hi
arver-side programming, security characteristics, and publishing, search engine,
ding tools that may come with it.
sJeading Web servers are Apache , the most widely-i
; 4 y-installed Web server,
Ys Internet Information Server (IS ). Other Web servers include Novell’
users of its NetWare operating system and IBM's family of Lotus Domi
: primarily for IBM’s 0S/390 and AS/400 custamers.
ces between local server and remote server:
‘or locally hosted solutions are commont i
r ly referred to as cli
‘small unit has a dedicated server on a site and the ope
d, In a local server solution, the physical medium on which tt
pred exist within the local area in which itis used or aecesse
referred to as server hosting. We access the
ng www. In such solutions, the physicalLP. University BCA)
is for Linux operating system
;AMP is for windows operating syste,
in for Mac OS X operating system,
Jampp is for X-O8, Apache, Mysai Py
What is LAMP SERVER? Yah Php, Peri,
Akash Books 2017-15
: LAMP Server is work on Linux O;
4, LAMPis a combine package of
5, Apache is the web server
.¢, Mysql is the relational database mana,
7. PHP is the object-oriented scripting La;
What is WAMP SERVER?
1, Full form of WAMP is Windows, Apache, MyS@L and PHP
2, This is an open source platform, 7
3. WAMP Server is work on Windows 0; ing Syster
4. LAMP is a combine package of Wiies kee ae
i oe » MySQL and PHP.
5. Apache is the web server
6. Mysql is the relational database management system,
7. PHP is the object-oriented scripting language.
What is MAMP SERVER?
1, Full form of MAMP is MAC, Apache, MySQL and PHP.
2, This is an open source platform.
3. MAMP Server is work on MAC Operating System only.
4, LAMP is a combine package of MAC, Apache, MySQL and PHP,
5. Apache is the web server
6, Mysq) is the relational database management system.
1, PHP is the object-oriented scripting language. ,
Q.3. (c) What is web application? Differentiate between client side scripting
and server side scripting. 6)
Ans. A web application or web app is any software that runs in a web browser.
Itis created in a browser-supported programming language (such as the combination
of JavaScript, HTML and CSS) and relies on a web browser to render the application.
‘The ability to update and maintain web applications without distributing and installing
software on potentially thousands of client computers is a key reason for their popularity,
asis the inherent support for cross-platform compatibility. Common web applications
include webmail, online retail sales, online auctions, wikis and many other functions.
Applications are usually broken into logical chunks called “tiers”, where every
erating System only,
Linux, Apache, MySQL and PHP.
iement system,
nguage,
is assigned a role. Traditional applications consist only of 1 tier, which
client machine, but web applications lend themselves to an n-tiered aj
‘Though many variations are possible, the most common sti
tiered application. In its most common form, the three tiers are
pplication and storage, in this order. A web browser is the first tie
engine using some dynamic Web content technology (such as
ISP/Java, PHP, Perl, Python, Ruby on Rails or
ley logic), and a database is the third tier (16-2017
requests to the middle tier, which services them by making queries
the databane and generates 9 ne
jlex applications, @
veils tee apenas ene
ic, which resides on the application tier, into a more
Fic ferences between client side scripting and server side scripting:
(4) Server side scripting is used to create dynamic pages based a number of
when the users browser makes a request to the server.
Client side scripting is used when the user's browser already has all the code
the page is altered on the basis of the users input.
(ii) The Web Server executes the server side scripting that produces the page to
sent to the browser.
‘The Web Browser executes the client side scripting that resides at the
computer.
(iii) Server executes server-side scripts to send out a page but it does not
client-side scripts.
‘The browser receives the page sent by the server and executes the client-side seri
(iv) Server side scripting is used to connect to the databases that reside on the
server.
Client side scripting cannot be used to counect to the databases on the web
(v) Server side scripting can access the file system residing at the web server.
Client side scripting can't access the file system that resides at the web server
(vi)The settings that belong to Web server can be accessed using Server sig
__ The files and settings that are local at the user’s computer can be accessed
it side scripting.
ii) Server side scripting can't be blocked by the user.
side scripting is possible to be blocked by the user.
‘Response from a server-side script is slower as compared to a cli
he scripts are processed on the remote computer.
from a client-side script is faster as compared to a set
e scripts are processed on the local computer.
of Server side scripting languages: PHP, JSP, ASP,ue Univervity-[HCA)-Akash Hooks WONT AY
The frat form loopn over the array given UPraY geprennion, Hteration,
value of the current clement i» ‘Manlgned wheer ond the inteareees whalers
tne ecco ae it arlene belong tine eee
ee second eel Ssalttoualiy uni Che CUFFORE olomant's kay to
Passing Argument by Reference
";
addSix( $orignum );
‘echo “Original Value is $orignum ";
me kery
Q. 4.(b) Differentiate numeric and associative array with example. we
PHP script to create a multidimensional array.
Ans. An array is a special variable, which can hold more than one value ac
‘There are three different kind of arrays and each array value is accessed using @
IDewhich is called array index.
* Indexed array — An array with a numericindex. Values are stored and accesse
in linear fashion
* Associative array — An array with strings as index. This stores element value
in asgociation with key values rather than in a strict linear index order.
PHP Indexed Arrays
‘These arrays can store numbers, strings and any object but their index will t
represented by numbers. By default array index starts from zero.
Example
Following is the example showing how to create and access numeric arrays. He,
‘we have used array() function to create array.
”;
}
/* Second method to create array. */
$numbers{0] = “one”;
$numbers{1} = “two”;LP. University{BCA}-Akash Books 2017-19
Arrays
gssocative arrays are very similar to numeric arrays in term of functionality
Bet Gre different in terms of their index. Associative array will have their index as
i ae ree a ee eeatinn bere ee eed
#75, sore the salaries employees in an array, a numerically indexed array would
es eee nn eats coat Sve ths plage emer Be ee
= Neve array, and the value would be their respective salary.
atsl>
aody>
2000,
“amit” => 1000,
“neha” => 500);
echo “Salary of ajay is “. $salaries{ajay] . “ ";
echo “Salary of amit is“. $salaries{amit]. “ ";
echo “Salary of neha is“. $salaries{neha]. “ ";
>
Multidimensional Arrays
‘A multi-dimensional array each element in the main array can also be an array.
fod each element in the sub-array can be an array, and so on. Values in the multi-
Gmensional array are accessed using multiple index. 5
Example
In this example we create a two dimensional array to store marks of three students
iethree subjects:\ g, Global variab!
Global sone rte
vriablos can be ace
| vorige a ciel varah
athe
“chemistry” => 39 $a= 5;
) | $b = 10;
, function myTest
. /* Accessing multi-dimensional array values */ '
‘echo “Marks for ajay in physics :* | Bae Pog
‘echo $markslajayll'physies'] “ "; a Saf '
‘echo “Marks for amit in maths *
7 myTest();,
echo $marks{amit}[‘maths') ‘echo $b;
echo “Marks for neha in cher eee
echo $smarks {nehall'chemistry’). “ "s Phe veri ab
& | __ PHP also store
| is the name of the
| be used to update
@.4.(c) Whats the scope of varlable. List and explain all'scopeofvariable) ‘The example
and super Globals variable in PHP with example. php
‘Ans. Scope can be defined as the range of availability a variable has tothe program) $a = 5;
in which it is declared. PHP variables can be one of four scope types: | $10;
1, Local variables : | function my
2, Global variables a
8, Static variables $GLOBALS{
4, Funetion parameters )
1. Local variables : myTest();
A variable declared within a PHP function is local an 0 ed with echo $b;
that function. (the variable has local scope): : b
3. Static variables
When a function is completed, all of its variables are normally deleted: However,
omernace you want a local variable to not be deleted. To do this, use the static keyword
when you first declare the variable:
static $rememberMe;
‘Then, each time the function is called, that variable,
tcontained from the last time the funetion was called.Fifth Semester, Web Based Programming
22-2017
Parameters are also called arguments
oR |
@.6. (a) Define constants in PHP with example. What are implicit “
and explicit casting in PHP?
‘Ans. Constants |
Constants are similar to variables, holding information to be accessed later, exce,
that thes ave what they sound like—constant. In other words, once you have defined
its value is set ‘am and cannot be altered. One example
‘rver root (the folder with th
for the remainder of the pro
tune fora constant might be to hold the loc
aun files of your website). You would define such a cons’
define(*“ROOT_LOCATION’, “/usr/local/www/"); % |
‘Then, to read the contents of the variable you just refer to it like a regular variably
(but it isn’t preceded by a dollar sign): a
$directory = ROOT_LOCATION;
Implicit and Explicit Casting pe
PEE We « Jooesly typed Inaguaye that allows youcadecians variable and its typ
simply by using it. It also automatically converts values from one type to anoth,
whenever required. This is called implicit casting. |
However, there may be times when PHP's i is not what you w:
Thea various ways in which this could be achieved. One way is 0, force the variable;
deere te on inteper value using the integer cast type (int); Uke this:
$c = Gint) ($a / $b); =
‘Thies called explicit casting. Note thatin order to ensure that the value of the.
expression is cast to an integer, the expression is placed within. parentheses.
only the variable $a would have been cast to an integer— pointless exercise, as th
Ghusic 3 by $b would still have returned a floating-point number.
PHP Cast Types
“Gast type Description
(nt) Ginteger) Gast to an integer by dropping the decimal portion
(ool) (boolean) Cast to a Boolean
(float) (double) (real) Cast to a floating-point number
(string) Cast to a string
Cast to an array
Cast to an object
5. (b) What is PHP. Explain data ty
Detwten exlae sal atinan? aLP. University{BCA}-Akash Books 2017-23
yroted and executed. PHP code
interite files, talk to remote se:
aun it types of dat
Different of data take up ditt
ntly when they are ination Pe apd
fore demand that the program:
en contain. PHP4 is loosely type:
gata is assigned to each variable.
in a script can query databases, create images, read
tvers— the possibilities are endless. .
its of memory and may be treated
lated in a script. Some programming languages
mer declare in advance which type of data a variable
'd, which means that it will calculate data types as.
Type Example Description
Integer 5 A whole number
Double 3.2 A floating-point number
Being “hello” A collection of characters
Boolean ‘True/false One of the special values true or false
Object
Array
Variables and Dynamic Variables
Variables: PHP is a very loosely typed language. This means that variables do not
have to be declared before they are used, and that PHP always converts variables to the
type required by their context when they are accessed.
Avariable is a special container that you can define to “hold” a value. A variable
consists of a name that you can choose, preceded by a dollar ($) sign. The variable name
can include letters, numbers, and the underscore character (_). Variable names cannot
include spaces or characters that are not alphanumeri
Dynamic Variables: As you know, you create a variable with a dollar sign followed
bya variable name. Unusually, the variable name can itself be stored in a variable. So,
when assigning a value to a variable
$user = “ajay”;
is equivalent to
$holder="user”;
$$holder = “ajay”;
‘The $holder variable contains the string “user”, so you can think of $$holder as a
dollar sign followed by the value of $holder. You can use a string constant to define a
dynamic variable instead of a variable. To do so, you must wrap the string you want to
use for the variable name in braces:
${*user”} = “ajay”;
$ $msg- is reference variable
$ msg — is normal variable
e.q: $ msg = “Santosh”;
$$ msg = “SINGH”;24-2017 Fifth Semester, Web Based Programming.
Q.5.(e) What are the different types of errors in PHP?
‘Ams. An error is a type of mistake, We can say an error is a condition of ha <
toe, SN inawetgn ox an errr ia defined as an unexpected, invalid progras
state from which it is possible to recover:
‘Types of Error
Basically there are four types of errors in PHP, which are as follows:
Parse error (Syntax error)
Fatal error
Warning error
‘The Parse error occurs if there is a syntax mistake in the script; the output is parse
ecxors A parse error stops the execution of the script. There are many reasons for the
‘Sccarrenee of parce errors in PHP. The common reasons are as follows:
* Unelosed quotes
+ Missing or Extra parentheses
= Unclosed braces
© Missing semicolon
Example
php
echo “cat”;
echo “Dog”
echo “Lion”;
>
Output: - In the above code we
‘happens there will be a parse error which s
missed semicolon in the second line, When that
tops execution of the script.
that you've written,LP. University{BCA}-Akash Books 2017-25
sample
Sprnion error”;
oon
> att In the above we include a [Link], however the [Link] file
Onrexistin the directory so there will be a warning ever produced but that does not
dees tye execution of the script i-e., you will see a message warning error.
HF Notice errors: Notice error is the same error as a warning error i.e., in the notice
.tion of the script does not stop. Notice that the error occurs when you try to
20 ‘he undefined variable, and then produce a notice error.
Example —
t:~ In the above code we defined a variable which named $a. but we call
y bariable $b which is not defined so there will be a notice error produced but
jon of the script does not stop, you will get a message notice error.
Q.6.(a) What is HTTP application state? (2.5)
‘Ans. Application state is used to store data on the application machine. It works
ss2 global variable in other programming languages. Application variable is an object
that is shared by the multiple sessions. We can use application variable within page,
HttpHandler and [Link].
When request a pagé from client machine, an instance will create at application
machine by the help of HttpApplicationState class. Entire application will have only
tne instance which is provided by HttpContext property named Application.
Q.6. (b) What are cookies? How can you create, access and delete a cookie in
PHP with the help of example. (5)
‘Ans. Cookies are text files stored on the client computer and they are kept of use
tracking purpose. PHP transparently supports HTTP cookies. It can contain almost any
alphanumeric information (as long as it” under 4KB) and can be retrieved from our
‘and returned to the server. Common uses include session tracking, maintaining
data across multiple visits, holding shopping cart contents, storing login details , and
more.
Dueto the way the Internet works, multiple elements on a web page can be embedded
from multiple domains, each of which can issue its own cookies. These are referred to as
‘third-party cookies. Most commonly, they are created by advertising companes in order
totrack users acrss multiple websites.
Cookies are exchanged during the transfer of headers, before the actual HTML ofa
‘web page is sent, and it is impossible to send a cookie once any HTML has been
transferred. Therefore, careful planning of cookie usage is important. Fol
shows a browser receiving two page: : ei
1 The browser issues a request to retrieve the main page, [Link], at
‘hittp:/ /[Link]. The first header specifies the field and the
| Specifies the server.26-2017 Fifth Semester, Web Based Programming
[Link] the web server at [Link] receives this pair ofheaders, it returns some
ofits own. The second header defines the type of content to be sent (text/html) and the
third one sends a cookie with the name name and the value value. Only then are the
contents of the web page transferred.
‘[Link] the browser has received the cookie, it will then return it with every future
request made to the issuing server until the cookie expires or is deleted. So, when the
browser requests the new page /[Link], it also returns the cookie name with value
‘4:Because the cookie has already been set , when the server receives the request 1¢
send /[Link], it does not have to resend the cookie, but just returns the requested
+ Setting a Cookie
PHP provided seteookie() function to set a cookie. This function requires Ome sit
vid wid be called before tag. For each cookie this fanction has
be called separately, Following is the syntax for setting a cookie :
setcookie(name, value, expire, path, domain, security);
Here is the detail of all the arguments:
called HTTP_COOKIE_VARS. This variable is
variable and is the content that you
* Value -This sets the value of the named
* Expiry - This specify a future time in seconds since [Link] GMT on Ast Jan
nb : x : badecee
closed.
« Path -This specifies the directories for which the cookie is valid.A single forwanj
slash character permits the cookie to be valid for all directories.
« Domain - This can be used to specify the domain name in very large domains ani
must contain at least two periods to be valid. All cookies are only valid for the host an
domain which created them.
'* Security - This can be set to 1 to specify that the cookie should only be sent y
secure transmission using HTTPS otherwise set to 0 which mean cookie can be senty
regular HTTP.
Following example will create two cookies name and age these cookies will
expired after one hour.
28-2017 Fifth Semester, Web Based Programming
|
ee |
|
}
whody> |
|
Q.6(c) What is File Handling in PHP? Write a PHP script to upload a file. |
Ans. File handling is an important part of any web application. You often need to |
‘open and process a file for different tasks. PHP has several functions for creating, reading,
uploading, and editing files.
At the time you are controlling files you must be extremely watchful on the grounds
that you can do a considerable measure of harm if something happens.
Regular errors include, editing the wrong file, filling a hard-drive with garbage data,
and incidentally erasing a file's content.
‘Normal errors include, editing the wrong file, filling a hard-drive with garbage data,
and accidentally deleting a file's content.
Creating and Deleting Files
Ifa file does not yet exist, you can create one with the touch() function. Given a string _
representing a file path, touch() attempts to create an empty file of that name. If the file
already exists, the contents are not disturbed, but the modification date is updated to
the time at which the function executed.
touch(“[Link]”);
‘You can remove an existing file with the unlink() function. Once again, unlink() |
vunlink(*[Link] |
‘Opening a File for Writing, Reading, or Appending i
Before you can work with a file, you must first open it for reading, writing, or both.
Py the fopen() function for this. fopen() requires a string containing the file
by a string containing the mode in which the file is to be opened. The
‘modes are read (‘’), write (‘w), and append (‘a’). fopen() returns an integer
“is known as a file pointer and should be assigned to a variable. To open a
would use the following:
:
j30-2017 Fifth Semester, Web Based ‘Programming
‘
";,
$fp = fopen( $filename, “w” ) or die(“Couldn’t op
fwrite( $fp, “Hello world\n” aE
eo
LP. University {BCA]-Akas
sh Books 2017-31
a sera ro) ?T8 an array ‘Ie not an array”;
? eit eto ened leh a eS ee
%
erent Sasingstamesfoyngeras Terma
I eA o(soards
f
rit, shuffle acts directly on the supplied array and returns TRUE on suctess
‘on eFTOF.
i Pe efal stee ith which
tat e u yn with which you can take a string containing several
no el pees character (or string of characters) and then place each of
items i
zexplode("*, “This is a sentence with seven words”);
print_r(Stemp);
>
‘his example prints out the following (on a single line when viewed ina browser):
array
is
{0) => This
(=is
(lea
[3] => sentence
[a}=> with
{5]=> seven
(6) => words
)
* extract()
Sometimes it can be convenient to turn the key/value pairs from an array into PHP
variables. One such time might be when processing the $_GET or $_POST variables as
sent to a PHP script by a form.
‘Ween a form issubmitied over the Web, the web server unpacks the variables i
variables were sent using the GET method, tley
global array for the PHP seript. Ifthe
be placed in an associative array called $- GET sna e sent using POST,
POST. :
will
thoy will be placed in an associative array called Bs
‘sometimes you just want to store the
this ease, you can have PHP do the job a32-2017 Fifth Semester, Web Based Programming
$city = “London”;
$country = “United Kingdom”;
’, ‘address’, ‘city’, ‘country’);
‘$contact = compact(‘fname’, ‘sname’,
=
* reset()
When the foreach...as construct or the each function walk through an array, they
keep an internal PHP pointer that makes a note of which element of the array they
should return next. If your code ever needs to return to the start of an array, you can
issue reset, which also returns the value of that element.
reseti$fred); // Throw away return value
an ‘= reset($frod); // Keep first element of the array in $item
»
‘he with reset, you ean move PHP's internal array pointer to the final element in an
array using the end function, which also returns the value of the element, and can be
used as in these examples:
end($fred);
$item = end($fred);
+ assort() >
‘This function sorts an array such that array indices maintain their correlation with,
the array elements they are associated with. This is used mainly when sorting
ae cclative arrays where the actual clement orders significant.
“lemon”, 4g” => “orange”, “b” =>
“banana”, “c” => “apple”);
assort($fruits);
foreach ($fruits as $key => $val) t
echo “$key = $val\n";
Converts a string to lowercase letters
Converts a string to uppercase letters
- ‘Translates certain characters in st
er than 30 seconds,
unt of time PHP allows scripts to.
ein your [Link] file,
execution time, use a
n your [Link]
your,LP. University-{BCA}-Akash
Books 2017-33
@») Write a PHP script to
ponent with in the database wi hale and create a
Department
oe Insert maximum two records and select einen oy eeename,
6)
‘ebody>
ae ‘= “root”;
ie “Department”; *
link = mysql_connect{ “localhost”, $user, $pass );
ec slink )
at Couldn't connect to MySQL” );
_select_db( $db, $link )
or die ( “Couldn’t open $db:” mysql_error() );
ery = “INSERT INTO employee (employee_id,employee_name,employee_age)
values( 100, ‘Amit 122)";
saysal_auery( $query, $link )
ardie ( “Couldn't add data to \” domains\“table:” mysql_error() );
mysql_close( $link );
>
ntml>
Program to select all records
$user = “root”;
$pass
$db = “Department”;
$link = mysql_connect( “localhost”, $user, $pass );
if(! $link )
die( “Couldn't connect to MySQL” );
mysaql_select_db( $db, $link )
or die (“Couldn't open $db:”.mysql_error() );
$result = mysql_query( “SELECT * FROM employee” );
$num_rows = mysql_num_rows( $result );
print “There are currently $num_rows rows in the table";
mysql_close $link );Web Based Programming:
eta width “10m"> Employee Namee/td>
Employee agec/td>
34-2017 Fith Semester,
| Sttd>tphp echo Srow( Employee. id) ytocitd>
-
‘
“
oR
she data in the result se
can retrieve tl
etween mysdi_fetch object
Q.9. (a) In how many ways we
‘using PHP? ‘What is the difference
mysql_fetch array?
data in the result sot of MySQL using PHP in 4 Wa 6
sult row as an enumerated array my}
"Ans. We can retrieve the
J, mysql_fetch_row >> Get a resi
sult row as associative and i
numeric array
2, mysql_fetch_array >> Fetch a rest
3, mysql_fetch_object >> Returns the current row ofa result set as an object
associative array.
T mysqlcfetch_assoc >> Fetch a result ow 8s On
‘mysq]_fetch_object0 is similar to ‘mysql fetch_array(), with one difference
a
ig returned, instead of an array. i
©) We a i Rua eos different data types in Mysq
eran aa "rem
Q isa database management system.
base is a structured collection of ae es peur ia i
ist toa picture gallery or the vast
ta stored i
aie wred in a computer database, you net
‘MySQL Server, Since compute
Ae mee a
"To add, access, and process
management system such
ta,
‘other applications, |te University-{BCA|-Akash Books 2017-35
on, requiring little or no attention. If you dedicate entire machine vad.
ganacjst the settings to take advantage oll the memory, CPU rence ‘at apy
available. MySQL can also scale up to clusters of machines, networked
Data Types in MYSQL: MySQL uses many different data types broken into three
categories: numeric, date and time, and string types.
i Numeric Data Types: MySQL uses all the standard ANSI SQL numeric data types,
s0 if you're coming to MySQL from a different database system, these definitions will
Seti ‘to you, The following list shows the common numeric data types and their
0 zed integer that can be signed or unsigned. If signed, the
allowable range is from -2147483648 to 2147483647. If unsigned, the allowable range
is from 0 to 4294967295. You can specify a width of up to 11 digits.
* TINYINT - A very small integer that can be signed or unsigned, If signed, the
allowable range is from -128 to 127. If unsigned, the allowable range is from 0 to 255.
‘You can specify a width of up to 4 digits.
+ SMALLINT - A small integer that can be signed or unsigned. If signed, the
allowable range is from -32768 to 32767. If unsigned, the allowable range is from 0 to
65535, You can specify a width of up to 5 digits.
* MEDIUMINT - A medium-sized integer that can be signed or unsigned. If
signed, the allowable range is from -8388608 to 8388607. If unsigned, the allowable
range is from 0 to 16777215. You can specify a width of up to 9 digits.
* BIGINT -A large integer that can be signed or unsigned. Ifsigned, the allowable
range is from -9223372036854775808 to 9223372036854775807. If unsigned, the -
allowable range is from 0 to 18446744073709561616. You ean specify a width of up to
igits.
* FLOAT(M,D) - A floating-point number that cannot be unsigned. You can define
the display length (M) and the number of decimals (D). This is not required and will
default to 10,2, where 2 is the number of decimals and 10 is the total number of digits
(including decimals). Decimal precision ean go to 24 places for a FLOAT.
+ DOUBLE(M,D) - A double precision floating-point number that cannot be
unsigned. You can define the display length (M) and the number of decimals (D). This is,
not required and will default to 16,4, where 4 is the number of decimals. Decimal
precision can go to 53 places for a DOUBLE. REAL is a synonym for DOUBLE.
+ DECIMAL(M,D) -An unpacked floating-point number that cannot be unsigned.
In ‘decimals, each decimal corresponds to one byte. Defining the display length
(M) and the number of decimals (D) is required. NUMERIC is a synonym for DECIMAL.
Date and Time Types: The MySQL date and time datatypes are:
+ DATE -A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31.
For example, December 30th, 1973 would be stored as 1973-12-30.
. FA chien ine abinatinasa Ye MD aa eae
between 1000-01-01 [Link] and 9999-12-31 ). ple,
December 30th, 1973 would be stored as 19:36-2017 Fifth Semester, Web Based Programming
© VARCHAR(ND -Avariable!
for example VARCHAR(5). You mus,
SILOB or TEXT - Aficld with
Large Obj Gare used to store lal
images or ol ,. Fields ‘defined as TEXT also hold large amounts of data.
the difference between the tw? Ta Ghat te oe an ‘stored data are cag,
sensitive on BLOBS eon, are not ease sensitive}? ‘elds, You do not specify a lengy,
‘with BLOB or TEXT. ‘apLOBor TEXT column wit
* TINYBLOB An SRO SRN
UM’ : or TE! aed
Miters. You do not eee
_ A BLOB or TEXT column with a maxi
length Teomy94967295 characters IT do not specify # length with TONGELON
LONGTEXT. Ae 3 : orl
. ENUM - An enumeration, which a fancy term for list. When defining an
you are ereating alistofitems OFT Ihe value must be selected (or can be NULL).
orexample, if you wanted your or “B” or “C”, you would define you.
a ABC) and only these va ILL) could ever populate that fig
Q.9. (c) Write connectivity and selecting database statement Which is usea
to connect PHP with MY: an
“Ans. Connecting | Server ‘
‘you can begin working wi database, you must first connect tothe,
fonction to do just this. ‘mysql_connect() does +
° gs: the hostname, a usename, Dak
rents, the function assumes Totaled
2 has been set up in the mysqluser re
fe. mysqi_connect() returns a li
yea cen value in avavicbey
ver. a
) to connect to the MySQL databas
server:
$link = mysql_connect( “Jocalhost”, “root”, “nickel” );
if(!$link) : .
die( “Couldn't connect to MySQL”); ”
ase
established a connection to the MySQL. d
work with. You can selectEND TERM EXAMINATION (DEC, 2
. 2018)
FIFTH SEMESTER [BCA]
WEB BASED PROGRAMMING [BCA-313]
ghee. pe MM. : 75
end ain any ~ Apsara inal including [Link], Lwhich is compulsory. Select one
{QL Attempt any Lon of the following,
(a) What is DAML? (2.5)
Ans. Dynamic HTML, or DETML, is
1 4n umbrella term for a collection of
gechnologies used together to create interactive and animated websites by using a
gombination of a static markup language (such as HTML), a client-side scripting
janguase (such as JavaScript), 4 presentation definition language (su CSS), and
the Document Object Model (DOM). The application of DHTML was introduced by
Microsoft with the release of Internet Explorer 4 in 1997,
DHTML allows scripting languages to change variables in a web page’s definition
Janguage, Which in turn affects the look and function of otherwise “static” HTML page
content, after the page has been fully loaded and during the viewing process, Thus the
dynamic characteristic of DHTML is the way it functions while a page is viewed, not in
its ability to generate a unique page with each page load.
Ans. The term “open source” refers to som
its design is publicly accessible."specify string when we wai
To specify a literal single
i
2-2018 Fifth Semester, Web Based Programming.
+ Remind yourself of what you did - Most programmers have experienced
scx Remind yourself wha rand having to re-figure oUt what they gat
Pane vents can remind you of what you were thinking when you wrote the code
PHP supports several ways of commenting: ;
G) // This is a single-line comment
(ii) # This is also a single-line comment
ain /*
This is a multiple-lines comment block
that spans over multiple
lines
¥
iv) //You ean also use comments to leave out parts of a code line
$x=5/* +157 +5;
echo $x;
Output is: 10
Q.1. (d) What is the difference between echo and print statement in PHP?
2.5)
Ans. Refer Q. 1. (b) Of End Term 2017
Q. 1. (e) What is phpinfo ()? (2.5)
‘Ans. phpinfo — Outputs information about PHP's configuration
phpinfo ({ int $what = INFO_ALL ]) : bool
tate of PHP. This includes
Outputs a large amount of information about the current st
information about PHP compilation options and extensions, the PHP version, server
information and environment (if compiled as a module), the PHP environment, OS
version information, paths, master and Jocal values of configuration options, HTTP
headers, and the PHP License.
Because every system is setup differently, phpinfo() is commonly used to check
configuration settings and for available predefined variables on a given system.
phpinfo() is also a valuable debugging tool as it contains all EGPCS (Environment,
GET, POST, Cookie, Server) data.
Q. 1. ( What is the difference between“ “and ‘*? (2.5)
Ans. Single Quoted Strings:
‘Single quoted strings are the easiest way to specify string. Single quote is used to
int the string to be exactly as it is written.
quote or backslash, escape it with a backslash (\). All
‘other escape sequences like \r or \n, will be output literally as s
having any special meaning.
: quotes , then PHP will not ev
‘When string is specified in single
characters except single quote with backslash (‘) and backs
you wanta variable tobe used with a single quoted St
riod to separate code in string because PHP will n