Lecture 45

IIT Kanpur July 201
20 followers
Oct 23, 2023
Good afternoon everyone, welcome to yet another lecture of the MOOCs course title web based
decision support system for engineers and practitioners.
This course as you have already gone through it that we are focusing more towards how decision
support system can be applied for various business problems especially from a practitioner
standpoint and how do we make decisions on the or about the unstructured decision making
problems associated with business.
And we have so far just as a recap of what the modules I have been covering we have seen
that if you look into the screen we have seen that we have a DSS or the web based DSS as
the central component in which we told we were having four components as part of it
and the first component was what we call as the DBMS or the database management system.
Then we talked about it was the what we call as MBMS the model based management system.
Then we called talked about as a KBMS knowledge based management system and the last one we
discussed was the UIMS user interface management system and the DBMS we have already seen things
like SQL we have seen the database and we have seen normalization and we also seen what
is MariaDB etcetera and how do we create databases etcetera as part of this.
And the user interface management system we have already seen aspects of HTML the UI UX
what it is and how do we design it a UI and a kind of a thing so forms etcetera we have
already seen that.
And we have mentioned at some point of time that the model based management system will
comprise of an application layer and building model libraries ok.
So there are multiple ways to do this but for the purpose of this course we are going
to do mostly here as a part of a PHP or a it is a server side scripting language that
is what we are going to study at the part of it and then the knowledge based management
system we will study towards the end of it and as mentioned earlier.
So this lecture is all about is introduction to PHP and the name PHP ok it is an very interesting
name because the name again the first P stands for PHP again and then the next is hypertext
and the preprocessor.
So this is the PHP expansion.
So the PHP appearing it again in the expansion of the acronym it is a very interesting way
of look we will talk about all this kind of things in this lecture.
So we are discussing specifically the PHP how PHP is used as an application program
or how does it actually builds the application layer and how does it also builds the model
how do you build the create the libraries of different decision models.
So today we have a brief introduction then references to basic language syntax data types
etc etc security and some features is what we will discuss today.
So originally if you think about it the PHP started as the personal home page 1994 this
is the beginning this is the initial avatar of PHP ok and the aim of this was the aim
at inception ok what was the aim at the inception a way to create dynamic web pages this is
the main interest at that time because remember few things HTML at that time created static
web pages ok.
So once you create a web page it is static it means the page does not change does not
change as per requirement whose requirement the requirement can be of two types it is
either the user requirement or the application program requirement either of the requirement
the HTML page did not change it remain the same.
So then the question was how to make these static pages static HTML pages into a dynamic
form this was the fundamental question from there what actually created was that develop
server side scripting language capable of creating HTML on the fly.
So this was a solution that was thought through so then that gave rise to PHP originally ok
that is how the PHP originated.
So we think about it that we wanted to bring the dynamic web pages or we wanted to create
dynamic web pages but at that time or in 1994 and all HTML resulted in what we call as static
web pages the web page content did not change once you create the web page it remained.
But the web page there were certain times are requirements either the requirement by
the user or by the application program to make the web page content change or dynamic.
So then the question arise was how to make this static HTML pages into a dynamic form
or a dynamic page and the solution developed was create a server side scripting language
that is capable of creating HTML on the fly or as the page is executed it should create
the HTML and that is how the PHP came into picture.
So the 1994 it started as personal home page as you see in the web page then in 1997 the
PHP 3 which is what the so this is the forefather of all versions of PHP we see now all versions
of current PHP's where PHP 4, PHP 5, PHP whatever it is you talk about it is all the
PHP.
So that became what you call as hypertext preprocessor so the core of the PHP which
is called as a zend engine presently it is also a framework zend is also a framework
but the zend engine is the one actually creates zend engine creates the HTML on fly or during
execution okay so that we are that is what we are talking about.
So the entire PHP code the zend engine was rewritten in 1997 and this naming of PHP as
I mentioned earlier PHP then the PHP appearing again then hypertext preprocessor this type
of naming is known as recronim okay or what we call as recursive acronym what is recursion?
Recursion is a function calling itself that is recursion.
So what is a recursive acronym?
So a recronim is a acronym that calls in itself.
So the PHP acronym calls it again so that is why it is called recursive acronym or recronim
or sometimes it is also known as recursive initialism.
So there are couple of other examples also.
So GNU okay is an example of it GNU is not UNIX so this is another example of it.
So that kind of things is there so PHP is an example of this you can see quite a lot
of the things that came out of the MIT lab actually followed this.
So what does PHP do?
So the main characteristics what are the main things number one the first thing is it develops
dynamic web pages.
It builds the web pages that are on the fly dynamic web pages or HTML when we talk about
web pages we are specifically talking about HTML.
Second thing is it does server side scripting.
So what does it actually happens is if you think about it what is the server side scripting?
So you have a let us say it is a laptop and you have a client sitting on it you working
on the laptop and then there is a connection.
So somewhere here there is a big server computer a big server connected to it so this is a
server and the server side scripting means the zend engine of PHP okay the zend engine
is present in the web server.
So the web server which is a server side application zend engine is present there.
So when the user accesses a particular web page the web server parses it or uses the
zend engine to dynamically create the HTML and sends it back.
So the user request comes this way and the so this is the request comes in and the dynamic
HTML goes back that is what it.
Now the third one is it is an interpreted language.
So there are two type of languages you may remember this in your earlier stuff one is
compiled and another one is called as interpreted okay.
So PHP is an interpreted language interpreted languages mean it is interpreted one line
at a time.
So it is like done at the time of execution one line at a time there is no compilation
absolutely no compilation going on.
And then the fourth point is that it contains HTML or it can embed HTML in your code that
is the main part of it and then the last part is it mostly follows C and Perl syntax.
C and Perl are two languages but C is a compiled language okay and Perl is an interpreted language
okay.
So it follows a syntax of both of this but it is in reality it is an interpreted language.
So I hope you guys have a reasonably okay idea about this.
So now let us you know move forward.
So what are some of the specifics of PHP what are some of these specialties associated with
PHP.
So as I said earlier you have a client laptop client computer let us use a laptop and then
there is a it is connected to a server this is a computer server.
The server has lot of things residing on it, it may have a DBMS, it have a web server,
it have a access server etc many aspects it will have.
So among the web server it will also include PHP capabilities which is realized by the
Zend engine.
So what happens is when the user sends a request then the code the PHP code gets executed on
the server.
So when the PHP code is executed PHP code execution is on the server it gets executed
on the server and what happens is in as part of the execution it generates HTML.
So that process is called parsing.
So the PHP code gets parsed to generate HTML.
So then this HTML is sent to the client machine the generated HTML at the server side is sent
to the client machine.
So the request from the client goes to the server and the generated HTML is sent back
to the client machine and what happens is that the client gets to see the so the client
sees only the resulting HTML ok.
The underlying PHP code ok that PHP code is hidden to the client the client never gets
to see the PHP code.
So the logic of how the web page is created is hidden from the client.
So what are major purposes or major uses of PHP number one is it is used in server side
scripting.
So specifically create dynamic HTML pages create server side application ok interconnect
DBMS to UI.
So those kind of etc.
All these are part of the server side aspects of PHP you can also do command line scripting
which means you can write a command line program.
So it is like writing a command line program it is a dot PHP program and can be executed
using the PHP that is also doable.
This will be an interpreted program interpreted by Zend engine and then writing desktop applications
can also write standalone desktop applications that is also third part of the PHP.
But the most important thing is most of the web servers ok that is available in the world
now they all support PHP.
So what is a web server?
So this question is obviously web server this keyword ok.
We talked about this web server here also what is it ok that is our next question.
So what is a web server?
The simplest answer to it is a it is a computer program web server is it is a computer program
and what does it does?
The two things it accepts HTTP request HTTP request is HTTP ok stands for hyper text transfer
protocol.
So if you see a web address it will say HTTP colon slash slash www.google.com ok this is
a request ok this means this is the user request to see Google web page ok.
You type it on the so where does this gets created ok.
So the request is typed on a browser of the client machine could be internet explorer
it could be up.
So what is a browser ok web browser it can be Firefox it can be this one what is called
chrome internet explorer etcetera ok they are all browsers.
So this request is created in the browser and then this request second thing is gets
transferred through internet until it reaches the server how does it reach using IP address
that contains the code the PHP code of the requested web page ok that is what happens.
Then what happens so once this is done the HTTP request it serves the HTTP request it
says show me the Google page and what it does is it creates the so serves the HTTP
request means generates resulting HTML code ok and if there is an optional data if there
is another data need to be fetched then the system will fetch that data and send it back.
So as of now the major web servers ok that are present in the world and their market
share as follows Apache this is the open source the free software foundation one which
is mostly majority 52 now it is 55 percent or something some people also call it as Tomcat
as well.
So it is another word actually it is a simpler version of it Apache Tomcat people called
Apache Tomcat either way.
So that is the majority is with them second one is IIS which is a proprietary ok this
is not an open source this is licensed software a Microsoft creates it it is internet information
system IIS stands for internet information system it is a second most popular but the
popularity is now somewhere in about 30 percent or something like that and then there is GWS
Google web server web server is about 6 to 8 percent is now this one and then there is
another one NGINX Google web server this is also is free but not open source free but
not open source and then NGINX is a minor 2 percent ok.
So in our discussion mostly when for we do in this class is we are focusing on Apache
plus PHP 5 is will consider as the standard or our we assume that this configuration is
available for us and then we build applications accordingly.
Now why we choose PHP 5 ok why PHP 5 this is an interesting question for us because
the two different types of programming styles and multiple programming styles many people
how so many depending upon whom you follow you will see different.
I broadly take three things one is called as the procedural programming second one is
what you call as the functional programming and the third one is called as the object
oriented programming as far as I am concerned these three are fine with me there is a some
distinction between procedural and functional I would like to distinguish them the procedural
programming is very commonly you can think about languages like cobalt or basic and all
they are good in and they have a go to kind of an usage also.
Functional programming is where you write the logic as multiple functions and call them
in a specific order so that is the functional program.
So object oriented programming is data plus methods combined ok so both the data and the
method or manipulation methods when means how to manipulate both are part of the object
oriented programming.
The PHP 5 allows both styles object oriented programming and functional programming I wrote
procedural programming because it also supports procedural programming.
So all sort of programming the three major programming styles that I am more worried
about it is supported by the PHP 5.
Second one is it supports a wide range of database management systems ok and this is
critical for developing DSS.
What are the wide range of DBMS that we support ok it supports MySQL, MariaDB, it supports
Postgres or PostgreSQL, it supports DBase, Oracle even it to an extent it supports even
what we call as Microsoft access this also happens etcetera ok.
The wide variety of database management support embedded into PHP makes it a very favorite
choice of the people who are developing DSS or decision support system.
Then third capability is it can generate images, PDF files and flash movies etcetera on the
fly.
So this is built in functions or canned operations packages available.
So you do not have to write a specific code for this anymore all this is already built
in you just have to call that operation or the package and say I want to create this
particular PDF file and PHP will create it for you and it also can process capabilities
to process text or XML documents ok or the XML stands for extended markup language.
So textual data processing capability that is also another important aspect of PHP 5
because of all these kind of reasons because it can support the object oriented programming,
it can support the functional programming, it can support the procedural programming,
it supports wide varieties of DBMS database management systems, it can create images,
PDF files, flash movies etcetera in a fly because all these things are built in as a
package you do not have to write the code it is available and you can also do textual
data processing.
All these aspects which are very critical for the decision support system is readily
available with PHP and especially in enhanced mode in PHP 5.
So we focus on PHP 5 or higher versions of it, so for us to design the web based decision
support system.
So what is the basic scripting structure or how is a basic PHP program?
So PHP program is also known as PHP script we are telling it as a PHP script the reason
why we call it as a script because it is a interpreted language line by line execution
just like a movie script you go line by line by line that is why it is called a PHP script.
Now the basic structure is it is enclosed within two tags, it is an opening tag and
a closing tag.
So opening tag is a less than sign a question mark and without any space PHP, so this when
this tag is encountered web server invokes zend engine for parsing PHP code okay.
As soon as the PHP tag this less than or equal to sign question mark and PHP comes
across this tag when it is encountered the web server whether it is IIS, whether it is
Apache, whether it is GWS does not matter they invoke the zend engine and that zend
engine parses the PHP code and how long it will continue to parse your PHP code like
this and at some place you will have a closing tag another question mark and a greater than
sign.
This tells the web server to close the parsing, so that is what the web server does.
So how does the web server know the intermediary is the web browser.
So through the web browser which are the web browsers Firefox, Internet Explorer, Chrome
etc. they are the web browsers okay through the web browser this web browser sends request
to web server.
So where is the web server residing it is residing on the computer server and then it
parses using zend engine and then sends the code back to the client or the web browser
which displaces and the PHP script files.
These files can be in two formats, there is two approved formats for this you can with
a dot html extension or a dot php extension.
So if I can say that hello dot html I can put php in this or I can dot create a file
called hello dot php and then put the php file in that or php code in that.
But also remember lot of the time people have this or when the people creating this application
they create this dot php files using word processors or notepad.
Word processor typically what I am talking about is Microsoft word and it can create
an issue usually the code may not parse purely because of the fact that the issue of carriage
return okay.
The way in which the enter when you for a new line how word processor handles new line
is an issue for the especially word processor and notepad can create an issue for your zend
engine.
So hence we recommend you to use if you are writing the php file think about this open
id this is an id integrated development environment php designer 2007 it is free it is easily
available in the website in the internet you can download it and write code accordingly
using this one right.
So this will prevent the issue of the carriage return when you are trying to learn the php
code.
So that is the basic php structure.
So let us create the first php program and once we go through this you may have a good
idea.
So first name the file as first underscore php dot html.
So as I remember we can elaborate this file.
So the content of the file is the first line is html then body you know and there is this
statement okay php.
So this tells that tells the web server to parse and then it goes to html.
So now let me elaborate this script okay let us elaborate this.
So html the minute you see this browser starts to parse the html.
It basically converts it is a markup language remember html is a markup language.
The other part of the html is head okay you can there is a head in which let us call it
as title my first php page slash title slash head okay.
So this finishes the header portion then we have what we call as the body.
So then somewhere within this is the slash body.
So the php scripts goes in the body portion.
So you can write here is h1 my first php scripted page or something like this slash h1.
So that will show up as a heading one.
Then I write it as php or you can write it as lower case also.
The minute this is this up to this point the web browser was doing it in the client machine
up to this point the web browser was doing it in the client machine.
Below this it will invoke zend at the server side.
So in the php we will say that use the keyword called echo okay.
Echo stands for print okay that is what it says display on to the crt what it is.
And within double quotes this is my first php scripts script output or something like
this okay.
So this echo means it just displays it on the screen and then you do this.
So this up to this much this is where the server side parsing happens and then what
we do is we say slash body that means the body component of the html part is over and
slash html the entire html code is also over.
So this kind of an approach where you are integrating or embedding php script in the
html file.
So this is one way of programming you in the html file itself you can create a php script
by giving this php opening and closing tag.
But remember every php code line ends with a semicolon.
So this is critical end of php code line every line should be done with the semicolon except
comments lines should not be done with the help of a semicolon.
So that is the other aspect.
So this whole file this entire thing can be saved as an html and when you open this html
file.
So let us say you put it on some server.
So you will write it as http://www.mywebserver.com slash first-php.html the minute you do this
assume that this file is saved in the root directory then this will be taken the web
browser will show you and print this is my this heading will be shown this will also
be shown and that will be the end of the program.
So this gives you a idea of how to create the first php program.
We will take a short break here and then we will do the next portion continue with the
more complicated programs php programs in the next session.
Thank you.
