SlideShare ist ein Scribd-Unternehmen logo
1 von 32
PHP Tutorial

                   By
    Mr. V. Kishore Kumar MCA (2009-12)


      Under the guidance of
    Mr. S. Amirtharaj M.E., &
    Mr. V. Neethidevan M.E.,
Contents
           • Introduction to PHP

           • Deploying PHP files

           • PHP Functions to
           interact with Mysql
06/07/12          MCA, Mepco Schlenk Engineering College, Sivakasi   2
Introduction to PHP




                         Contents
06/07/12       MCA, Mepco Schlenk Engineering College, Sivakasi   3
PHP
• PHP stands for PHP: Hypertext Preprocessor
• PHP is a powerful tool for making dynamic and
  interactive Web pages.
• PHP is a server-side scripting language, like ASP
• PHP scripts are executed on the server
• PHP supports many databases (MySQL, Informix,
  Oracle, Sybase, Solid, PostgreSQL, Generic
  ODBC, etc.)
• PHP is an open source software


06/07/12         MCA, Mepco Schlenk Engineering College, Sivakasi   4
What is a PHP file ?
• PHP files can contain text, HTML tags and
  scripts
• PHP files are returned to the browser as plain
  HTML
• PHP files have a file extension of ".php",
  ".php3", or ".phtml"



06/07/12        MCA, Mepco Schlenk Engineering College, Sivakasi   5
Why PHP ?
• PHP runs on different platforms (Windows,
  Linux, Unix, etc.)
• PHP is compatible with almost all servers used
  today (Apache, IIS, etc.)
• PHP is FREE to download from the official PHP
  resource: www.php.net
• PHP is easy to learn and runs efficiently on the
  server side

06/07/12        MCA, Mepco Schlenk Engineering College, Sivakasi   6
Where to Start ?
To get access to a web server with PHP support,
  you can:
• Install Apache (or IIS) on your own server,
  install PHP, and MySQL
• Or install WAMP s/w for windows, LAMP for
  Linux to easily develop web applications in
  PHP
     WAMP – Windows Apache Mysql & PHP
     LAMP – Linux Apache Mysql & PHP

06/07/12         MCA, Mepco Schlenk Engineering College, Sivakasi   7
PHP Basics
• The PHP script is executed on the server, and the plain
  HTML result is sent back to the browser
• A PHP script always starts with <?php and ends with ?>
• A PHP script can be placed anywhere in the document
• A PHP file normally contains HTML tags, and some PHP
  scripting code
• Each code line in PHP must end with a semicolon.
• The semicolon is a separator and is used to distinguish
  one set of instructions from another.


06/07/12           MCA, Mepco Schlenk Engineering College, Sivakasi   8
Sample file
<html>
<body>

<?php
echo "Hello World";
?>

</body>
</html>


Echo – output text in PHP.

There are two basic statements to output text with PHP: echo and print



06/07/12                     MCA, Mepco Schlenk Engineering College, Sivakasi   9
Comments in PHP
In PHP, we use // to make a one-line comment or /* and */ to make a comment
block:

<html>
<body>

<?php
//This is a comment

/*
This is
a comment
block
*/
?>

</body>
</html>
06/07/12                 MCA, Mepco Schlenk Engineering College, Sivakasi   10
PHP Variables
• Variables in PHP starts with a $ sign, followed by the
  name of the variable
• The variable name must begin with a letter or the
  underscore character
• A variable name can only contain alpha-numeric
  characters and underscores (A-z, 0-9, and _ )
• A variable name should not contain spaces
• Variable names are case sensitive (y and Y are two
  different variables)

06/07/12           MCA, Mepco Schlenk Engineering College, Sivakasi   11
Creating or Declaring PHP
Variables
• PHP has no command for declaring a variable

           <?php
           $txt="Hello World!";
           $x=16;
           ?>

• PHP is a loosely typed language, automatically converts
  the variable to the correct data type, depending on its
  value
  Note: When you assign a text value to a variable, put
  quotes around the value

06/07/12                    MCA, Mepco Schlenk Engineering College, Sivakasi   12
The Concatenation Operator
• The concatenation operator (.) is used to put two
  string values together
           <?php
           $txt1="Hello World!";
           $txt2="What a nice day!";
           echo $txt1 . " " . $txt2;
           ?>

• The output of the code above will be:
           Hello World! What a nice day!

Note : Operators, if..else, switch, loops & etc. are all same as of C syntax.


06/07/12                    MCA, Mepco Schlenk Engineering College, Sivakasi   13
PHP Forms
• The most important thing to notice when dealing with HTML
  forms and PHP is that any form element in an HTML page
  will automatically be available to your PHP scripts
           <html>
           <body>
           <form action="welcome.php" method="post">
           Name: <input type="text" name="fname" />
           Age: <input type="text" name="age" />
           <input type="submit" />
           </form>
           </body>
           </html>

• When a user fills out the form above and clicks on the submit
  button, the form data is sent to a PHP file, called
  "welcome.php":
06/07/12                  MCA, Mepco Schlenk Engineering College, Sivakasi   14
“welcome.php”
           <html>
           <body>

           Welcome <?php echo $_POST["fname"]; ?>!<br />
           You are <?php echo $_POST["age"]; ?> years old.

           </body>
           </html>


Output
           Welcome John!
           You are 28 years old.

•   Note: $_POST[“ “] specifies how the input value passed from another
    form or page is get into new PHP scripting page

06/07/12                   MCA, Mepco Schlenk Engineering College, Sivakasi   15
PHP $_GET Function

• Collect values in a form with method=“get”
• While using this method all values are displayed in
  URL.

PHP $_POST Function
• Collect values in a form with method=“post”
• While using this method all values are not displayed
  (invisible to others) in URL.



06/07/12           MCA, Mepco Schlenk Engineering College, Sivakasi   16
Deploying PHP files




                        Contents
06/07/12       MCA, Mepco Schlenk Engineering College, Sivakasi   17
Windows

• Install WAMP Web-Server Software and
  deploy all your applications.
• Consider you have installed WAMP on “C:”
  Drive. Then place all your .php files in the
  following folder “C:wampwww”
• For further instructions please refer
     http://www.tinkertech.net/tutor/wamp/index.html


06/07/12           MCA, Mepco Schlenk Engineering College, Sivakasi   18
Fedora

• Save your php files into “varwwwhtml”
  folder. To place your files first we have to set
  access permissions.

Follow the given steps below
• Open the Terminal.
• Log in as Super User. Type “su” command it
  will ask for root password ( ask the technicians or
  respective faculties).
06/07/12          MCA, Mepco Schlenk Engineering College, Sivakasi   19
Follow the steps (contd..)
• Next step is to change our current working
  location.
• Type “cd ..” as many times until your present
  working directory(can be found by using pwd
  command) reaches “/”.
• Type cd var/www.
• Type “ls” it will list all the files & directories
  present in that directory. We have to deploy
  our php files under HTML.

06/07/12         MCA, Mepco Schlenk Engineering College, Sivakasi   20
Follow the steps (contd..)
            To set access permission to HTML folder use
            chmod command
            type chmod 777 html.
            Now you have set the access permissions to
            that folder. We can paste any files in under that
            folder.

To display our PHP files in Browser,
• Before opening browser, ensure that apache
  services is running or not.

06/07/12               MCA, Mepco Schlenk Engineering College, Sivakasi   21
• (In Browser) Type “localhost” in url and press
  enter. If the apache services is running
  correctly, it will shows fedora test page as
  shown below.




06/07/12        MCA, Mepco Schlenk Engineering College, Sivakasi   22
• If it shows “Problems on page load error”
  means, the apache services is not running.
  open terminal (enter as super user (“su”))

      – Type apchectl start – to start the apache server.
      – Type apchectl stop – to stop the apache server.
        (its not mandatory to stop).
• Note : create separate folders for your php
  project under HTML folder
  Ex: if folder name is “test”, then in url type as
     localhost/test/yourphpfilename along with .php extension

06/07/12              MCA, Mepco Schlenk Engineering College, Sivakasi   23
PHP Functions to interact with
               Mysql




                        Contents
06/07/12     MCA, Mepco Schlenk Engineering College, Sivakasi   24
MySql
• Most popular open-source database system
• We can create any number of databases under
  particular databases we can create any number
  of tables.
• Mysql GUI has been available in the market,
  which allows us to add, edit, modify records,
  tabels, databases easily


06/07/12       MCA, Mepco Schlenk Engineering College, Sivakasi   25
Steps to be followed in Fedora environment to
  use Mysql
• Log in as super user in terminal by using “su”
  command
• Then type mysql
• To lists all existing databases, type show
  databases;
• To select a database, type use database_name;
• to lists all tables exists under that database, type
  show tables;
• Note: Tables can be created only by selecting a
  database first.

06/07/12           MCA, Mepco Schlenk Engineering College, Sivakasi   26
PHP Functions to access MySql
     Before you can access data in a database,
 you must create a connection to the database.
 In PHP, this is done with the mysql_connect()
 function.

mysql_connect(servername,username,passwo
 rd);




06/07/12       MCA, Mepco Schlenk Engineering College, Sivakasi   27
Ex :-)
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
mysql_close($con);
?>
06/07/12        MCA, Mepco Schlenk Engineering College, Sivakasi   28
• The connection will be closed automatically
  when the script ends. To close the connection
  before, use the mysql_close() function.
• mysql_select_db() -> Sets the current active
  database on the server that's associated with
  the specified link identifier. Every subsequent
  call to mysql_query() will be made on the
  active database.
• mysql_query() -> executes the INSERT
  INTO statement, and a new record will be
  added to the table.
06/07/12        MCA, Mepco Schlenk Engineering College, Sivakasi   29
• mysql_num_rows() -> Retrieves the number
  of rows from a result set. This command is
  only valid for statements like SELECT or
  SHOW that return an actual result set. To
  retrieve the number of rows affected by a
  INSERT, UPDATE, REPLACE or DELETE
  query, use mysql_affected_rows().
• mysql_fetch_array() -> return the first row
  from the recordset as an array. Each call to
  mysql_fetch_array() returns the next row in
  the recordset.

06/07/12        MCA, Mepco Schlenk Engineering College, Sivakasi   30
Sample program to display data from database :
Ex:
mysql_connect("localhost","root","");
mysql_select_db("my_db");
$result = mysql_query("SELECT * FROM Persons");
while($row = mysql_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />";
}

The while loop loops through all the records in the
  recordset. To print the value of each row, we use the
PHP $row variable ($row['FirstName'] and
  $row['LastName']).
06/07/12           MCA, Mepco Schlenk Engineering College, Sivakasi   31
06/07/12   MCA, Mepco Schlenk Engineering College, Sivakasi   32

Weitere ähnliche Inhalte

Was ist angesagt?

Osp ii presentation
Osp ii presentationOsp ii presentation
Osp ii presentationpresse_jkp
 
Introduction to webprogramming using PHP and MySQL
Introduction to webprogramming using PHP and MySQLIntroduction to webprogramming using PHP and MySQL
Introduction to webprogramming using PHP and MySQLanand raj
 
PHP and Web Services
PHP and Web ServicesPHP and Web Services
PHP and Web ServicesBruno Pedro
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida realPHP Conference Argentina
 
Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)Ivo Jansch
 
PHP presentation - Com 585
PHP presentation - Com 585PHP presentation - Com 585
PHP presentation - Com 585jstout007
 
Php hypertext pre-processor
Php   hypertext pre-processorPhp   hypertext pre-processor
Php hypertext pre-processorSiddique Ibrahim
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjsPeter Edwards
 

Was ist angesagt? (20)

Dynamic Web Programming
Dynamic Web ProgrammingDynamic Web Programming
Dynamic Web Programming
 
Phpbasics
PhpbasicsPhpbasics
Phpbasics
 
Osp ii presentation
Osp ii presentationOsp ii presentation
Osp ii presentation
 
Introduction to webprogramming using PHP and MySQL
Introduction to webprogramming using PHP and MySQLIntroduction to webprogramming using PHP and MySQL
Introduction to webprogramming using PHP and MySQL
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
 
PHP and Web Services
PHP and Web ServicesPHP and Web Services
PHP and Web Services
 
Php unit i
Php unit iPhp unit i
Php unit i
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
20jsp
20jsp20jsp
20jsp
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
 
Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)
 
PHP presentation - Com 585
PHP presentation - Com 585PHP presentation - Com 585
PHP presentation - Com 585
 
Php hypertext pre-processor
Php   hypertext pre-processorPhp   hypertext pre-processor
Php hypertext pre-processor
 
php
phpphp
php
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjs
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Ähnlich wie PHP Introduction ( Fedora )

PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessoradeel990
 
PHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHPPHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHPLariya Minhaz
 
Web programming
Web programmingWeb programming
Web programmingIshucs
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they doDave Stokes
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPtutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPtutorialsruby
 
Create dynamic sites with PHP & MySQL
Create dynamic sites with PHP & MySQLCreate dynamic sites with PHP & MySQL
Create dynamic sites with PHP & MySQLkangaro10a
 
Develop PHP Applications with MySQL X DevAPI
Develop PHP Applications with MySQL X DevAPIDevelop PHP Applications with MySQL X DevAPI
Develop PHP Applications with MySQL X DevAPIDave Stokes
 
PHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentPHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentEdureka!
 

Ähnlich wie PHP Introduction ( Fedora ) (20)

Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessor
 
wamp.ppt
wamp.pptwamp.ppt
wamp.ppt
 
PHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHPPHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHP
 
Web programming
Web programmingWeb programming
Web programming
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
 
My Saminar On Php
My Saminar On PhpMy Saminar On Php
My Saminar On Php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php with mysql ppt
Php with mysql pptPhp with mysql ppt
Php with mysql ppt
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Chp 08 php (shared)
Chp 08   php  (shared) Chp 08   php  (shared)
Chp 08 php (shared)
 
Create dynamic sites with PHP & MySQL
Create dynamic sites with PHP & MySQLCreate dynamic sites with PHP & MySQL
Create dynamic sites with PHP & MySQL
 
Develop PHP Applications with MySQL X DevAPI
Develop PHP Applications with MySQL X DevAPIDevelop PHP Applications with MySQL X DevAPI
Develop PHP Applications with MySQL X DevAPI
 
PHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentPHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web Development
 
Phphacku iitd
Phphacku iitdPhphacku iitd
Phphacku iitd
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 

Kürzlich hochgeladen

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Kürzlich hochgeladen (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

PHP Introduction ( Fedora )

  • 1. PHP Tutorial By Mr. V. Kishore Kumar MCA (2009-12) Under the guidance of Mr. S. Amirtharaj M.E., & Mr. V. Neethidevan M.E.,
  • 2. Contents • Introduction to PHP • Deploying PHP files • PHP Functions to interact with Mysql 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 2
  • 3. Introduction to PHP Contents 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 3
  • 4. PHP • PHP stands for PHP: Hypertext Preprocessor • PHP is a powerful tool for making dynamic and interactive Web pages. • PHP is a server-side scripting language, like ASP • PHP scripts are executed on the server • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) • PHP is an open source software 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 4
  • 5. What is a PHP file ? • PHP files can contain text, HTML tags and scripts • PHP files are returned to the browser as plain HTML • PHP files have a file extension of ".php", ".php3", or ".phtml" 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 5
  • 6. Why PHP ? • PHP runs on different platforms (Windows, Linux, Unix, etc.) • PHP is compatible with almost all servers used today (Apache, IIS, etc.) • PHP is FREE to download from the official PHP resource: www.php.net • PHP is easy to learn and runs efficiently on the server side 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 6
  • 7. Where to Start ? To get access to a web server with PHP support, you can: • Install Apache (or IIS) on your own server, install PHP, and MySQL • Or install WAMP s/w for windows, LAMP for Linux to easily develop web applications in PHP WAMP – Windows Apache Mysql & PHP LAMP – Linux Apache Mysql & PHP 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 7
  • 8. PHP Basics • The PHP script is executed on the server, and the plain HTML result is sent back to the browser • A PHP script always starts with <?php and ends with ?> • A PHP script can be placed anywhere in the document • A PHP file normally contains HTML tags, and some PHP scripting code • Each code line in PHP must end with a semicolon. • The semicolon is a separator and is used to distinguish one set of instructions from another. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 8
  • 9. Sample file <html> <body> <?php echo "Hello World"; ?> </body> </html> Echo – output text in PHP. There are two basic statements to output text with PHP: echo and print 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 9
  • 10. Comments in PHP In PHP, we use // to make a one-line comment or /* and */ to make a comment block: <html> <body> <?php //This is a comment /* This is a comment block */ ?> </body> </html> 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 10
  • 11. PHP Variables • Variables in PHP starts with a $ sign, followed by the name of the variable • The variable name must begin with a letter or the underscore character • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • A variable name should not contain spaces • Variable names are case sensitive (y and Y are two different variables) 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 11
  • 12. Creating or Declaring PHP Variables • PHP has no command for declaring a variable <?php $txt="Hello World!"; $x=16; ?> • PHP is a loosely typed language, automatically converts the variable to the correct data type, depending on its value Note: When you assign a text value to a variable, put quotes around the value 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 12
  • 13. The Concatenation Operator • The concatenation operator (.) is used to put two string values together <?php $txt1="Hello World!"; $txt2="What a nice day!"; echo $txt1 . " " . $txt2; ?> • The output of the code above will be: Hello World! What a nice day! Note : Operators, if..else, switch, loops & etc. are all same as of C syntax. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 13
  • 14. PHP Forms • The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts <html> <body> <form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> • When a user fills out the form above and clicks on the submit button, the form data is sent to a PHP file, called "welcome.php": 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 14
  • 15. “welcome.php” <html> <body> Welcome <?php echo $_POST["fname"]; ?>!<br /> You are <?php echo $_POST["age"]; ?> years old. </body> </html> Output Welcome John! You are 28 years old. • Note: $_POST[“ “] specifies how the input value passed from another form or page is get into new PHP scripting page 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 15
  • 16. PHP $_GET Function • Collect values in a form with method=“get” • While using this method all values are displayed in URL. PHP $_POST Function • Collect values in a form with method=“post” • While using this method all values are not displayed (invisible to others) in URL. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 16
  • 17. Deploying PHP files Contents 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 17
  • 18. Windows • Install WAMP Web-Server Software and deploy all your applications. • Consider you have installed WAMP on “C:” Drive. Then place all your .php files in the following folder “C:wampwww” • For further instructions please refer http://www.tinkertech.net/tutor/wamp/index.html 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 18
  • 19. Fedora • Save your php files into “varwwwhtml” folder. To place your files first we have to set access permissions. Follow the given steps below • Open the Terminal. • Log in as Super User. Type “su” command it will ask for root password ( ask the technicians or respective faculties). 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 19
  • 20. Follow the steps (contd..) • Next step is to change our current working location. • Type “cd ..” as many times until your present working directory(can be found by using pwd command) reaches “/”. • Type cd var/www. • Type “ls” it will list all the files & directories present in that directory. We have to deploy our php files under HTML. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 20
  • 21. Follow the steps (contd..)  To set access permission to HTML folder use chmod command  type chmod 777 html.  Now you have set the access permissions to that folder. We can paste any files in under that folder. To display our PHP files in Browser, • Before opening browser, ensure that apache services is running or not. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 21
  • 22. • (In Browser) Type “localhost” in url and press enter. If the apache services is running correctly, it will shows fedora test page as shown below. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 22
  • 23. • If it shows “Problems on page load error” means, the apache services is not running. open terminal (enter as super user (“su”)) – Type apchectl start – to start the apache server. – Type apchectl stop – to stop the apache server. (its not mandatory to stop). • Note : create separate folders for your php project under HTML folder Ex: if folder name is “test”, then in url type as localhost/test/yourphpfilename along with .php extension 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 23
  • 24. PHP Functions to interact with Mysql Contents 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 24
  • 25. MySql • Most popular open-source database system • We can create any number of databases under particular databases we can create any number of tables. • Mysql GUI has been available in the market, which allows us to add, edit, modify records, tabels, databases easily 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 25
  • 26. Steps to be followed in Fedora environment to use Mysql • Log in as super user in terminal by using “su” command • Then type mysql • To lists all existing databases, type show databases; • To select a database, type use database_name; • to lists all tables exists under that database, type show tables; • Note: Tables can be created only by selecting a database first. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 26
  • 27. PHP Functions to access MySql Before you can access data in a database, you must create a connection to the database. In PHP, this is done with the mysql_connect() function. mysql_connect(servername,username,passwo rd); 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 27
  • 28. Ex :-) <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } // some code mysql_close($con); ?> 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 28
  • 29. • The connection will be closed automatically when the script ends. To close the connection before, use the mysql_close() function. • mysql_select_db() -> Sets the current active database on the server that's associated with the specified link identifier. Every subsequent call to mysql_query() will be made on the active database. • mysql_query() -> executes the INSERT INTO statement, and a new record will be added to the table. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 29
  • 30. • mysql_num_rows() -> Retrieves the number of rows from a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use mysql_affected_rows(). • mysql_fetch_array() -> return the first row from the recordset as an array. Each call to mysql_fetch_array() returns the next row in the recordset. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 30
  • 31. Sample program to display data from database : Ex: mysql_connect("localhost","root",""); mysql_select_db("my_db"); $result = mysql_query("SELECT * FROM Persons"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } The while loop loops through all the records in the recordset. To print the value of each row, we use the PHP $row variable ($row['FirstName'] and $row['LastName']). 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 31
  • 32. 06/07/12 MCA, Mepco Schlenk Engineering College, Sivakasi 32