SlideShare a Scribd company logo
PHP and MySQL
PHP Language A recursive acronym:  P HP  H ypertext  P reprocessor A scripting language designed for creating dynamic and data-driven Web pages  PHP is a server-side scripting language; it is parsed and interpreted on the server side of a Web application and the resulting output is sent to the browser. (VBScript and JavaScript are mostly client-side). Designed to work with the MySQL database system, but can also connect to other database systems.
PHP Language PHP and MySQL are open-source; they can be obtained free-of-charge and the source codes are available for development. www.php.net www.mysql.com You will need to install PHP to work with your MS IIS or Apache Web server. PHP and MySQL are becoming increasingly popular in recent years because it is free of charge. Other software packages like Microsoft ASP.NET are expensive for small and medium enterprises.
A Simple PHP Example <HTML> <HEAD> <TITLE>PHP Example</TITLE> </HEAD> <BODY> <? echo &quot;<b>Welcome</b>&quot;; // print the string here ?> </BODY> </HTML> PHP scripts are enclosed by the  <?php  And  ?>  tags. Can simply use  <?  for the opening tag. All PHP statements end with a semicolon (unless it ends the closing tag on the same line) ‏ Comments can be marked by  # ,  //  or  /* */ http://147.8.210.143/php/example1.php
Including Files You can include common files (like header, footer, and navigation bars) in PHP. <? include(&quot;header.inc&quot;) ?>
Variables in PHP Variable names start with the dollar sign $ You can use letters and underscore for variable names.  The first character after $ cannot be a number Variable names are case-sensitive For example: <? $name = &quot;Michael&quot;; ?> <? $i = 1; ?>
Variables in PHP The three main types of variables in PHP: Scalar Array Object Scalar can be Integer, Double, Boolean, or String When you assign a value to a variable, its data type is also assigned.
Array Arrays can be created with integers or strings as keys.  <?php $arr = array(&quot;UK&quot; => &quot;London&quot;, 12 => 56); echo $arr[&quot;UK&quot;]; // London echo $arr[12];    // 56 ?>
Object Use the  class  statement to define a class. Use the  new  statement to create an object. <?php class test {    function do_something()    {        echo &quot;Do something&quot;;     } } $my_test = new test; $my_test->do_something(); ?>
Basic Operators Assignment/Arithmetic operators = + - * / % ++ -- += -= *= /= Comparison operators ==  (equal value) ‏ ===  (identical value and data type) ‏ !=  or  <> < > <= >= Logical operators ! && ||
String Concatenation Same as Perl . concatenate strings .=  concatenate and assign Example: $word1 = &quot;Play&quot;;  $full_string = $word1 . &quot;Station&quot;;
String Functions There are a lot of string functions in PHP that you can use. For example: int strlen(string str) ‏ string strtoupper(string str) ‏ string strtolower(string str) ‏ int strcmp(string str1, string str2) ‏ int strcasecmp(string str1, string str2) ‏ string strstr(string src, string target) ‏ int strpos(string src, string target [, int offset]) ‏ You can find them in the PHP manual: http://www.php.net/manual/en/
Conditions boolean variable: TRUE(1) or FALSE(0) ‏ if (EXPR) { STATEMENTS; }  elseif (EXPR) { STATEMENTS; } else { STATEMENTS; } switch-case
Loops while ( EXPR )  { STATEMENTS; }  do { STATEMENTS;  } while (EXPR); for ( INIT_EXPR; COND_EXPR; LOOP_EXPR )  { STATEMENTS; }   foreach (ARRAY as VARIABLE)  { STATEMENTS; } break, continue
Alternative Syntax It is possible to write control statements and loops using the following “colon” format: <?php  if ($a == 5):   echo &quot;A is equal to 5&quot;;  endif; ?>
User-defined Functions Functions can be defined using the  function  keyword. <?php function function_name($arg_1, $arg_2, ...) {    statements;    return $some_value; // optional  } ?>
Mixing HTML and PHP Codes PHP codes can be easily inserted anywhere in an HTML page.  You can even mix the codes together, usually to avoid writing too many “echo” statements with escape characters. <?  if ($i == 1) {  ?>   <h2>The condition is true</h2>   <center><b>$i is 1</b></center> <?  } else {  ?>   <h2>The condition is false</h2>   <center><b>$i is not 1</b></center> <?  }  ?>  HTML PHP
Shortcut for Writing Echos Instead of writing  <? echo expression ?> You can use the following shortcut <?= expression ?> This is useful for inserting expressions and variables quickly into HTML pages.
Working with HTML Forms You can easily get the variables submitted by an HTML form using the following (assume the form input is called “name”: $_POST['name'] // post method $_GET['name'] // get method $name /* easier, but Register Globals must be set to ON in PHP config */
Working with HTML Forms It is common to put the form and the results of different requests in the same file. <HTML> <HEAD><TITLE>PHP FORM TEST</TITLE></HEAD> <BODY> <? if (!isset($name) || $name == &quot;&quot;) { ?> <FORM METHOD=&quot;post&quot;> Your name: <INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot;> Your age: <INPUT TYPE=&quot;text&quot; NAME=&quot;age&quot;> <INPUT TYPE=&quot;submit&quot;> </FORM> <? } else { echo &quot;Your name is $name<BR>&quot;; echo &quot;Your age is $age&quot;; } ?> </BODY> </HTML> If name is empty or not defined, then show the form If name is not empty, i.e., when the user has entered something, then show the results http://localhost/php/example2.php
PHP and MySQL PHP is designed to work with the MySQL database. However, it can also connect to other database systems such as Oracle, Sybase, etc., using ODBC.
Example <HTML> <BODY>  <?php  $db = mysql_connect(&quot;localhost&quot;, &quot;root“,””);  mysql_select_db(&quot;mydb &quot; , $db);  $result = mysql_query(&quot;SELECT * FROM employees&quot;,$db);  printf(&quot;First Name: %s<br>\n&quot;, mysql_result($result,0,&quot;first&quot;));  printf(&quot;Last Name: %s<br>\n&quot;, mysql_result($result,0,&quot;last&quot;));  printf(&quot;Address: %s<br>\n&quot;, mysql_result($result,0,&quot;address&quot;));  printf(&quot;Position: %s<br>\n&quot;,mysql_result($result,0,&quot;position&quot;));  mysql_free_result($result); mysql_close($db); ?>  </BODY> </HTML>
Useful PHP Functions for MySQL mysql_connect(host, username [,password]); Connects to a MySQL server on the specified host using the given username and/or password. Returns a MySQL link identifier on success, or FALSE on failure.  mysql_select_db(db_name [,resource]) ‏ Selects a database from the database server.
Useful PHP Functions for MySQL mysql_query(SQL, resource);  Sends the specified SQL query to the database specified by the resource identifier. The retrieved data are returned by the function as a MySQL result set.  mysql_result(result, row [,field]);  Returns the contents of one cell from a MySQL result set. The field argument can be the field name or the field’s offset. mysql_fetch_array(result [,result_type]) ‏ Fetch a result row as an associative array, a numeric array, or both. The result type can take the constants MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH.
Useful PHP Functions for MySQL mysql_free_result(result) ‏ Frees the result set mysql_close(resource) ‏ Closes the connection to the database.
Error Handling If there is error in the database connection, you can terminate the current script  by using the  die  function. For example: $db = mysql_connect(&quot;localhost&quot;, &quot;root“, “”)  or die(&quot;Could not connect : &quot; . mysql_error()); mysql_select_db(&quot;my_database&quot;)  or die(&quot;Could not select database&quot;); $result = mysql_query($query)  or die(&quot;Query failed&quot;);
Example: Looping through the Cells <?php /* Connecting, selecting database */ $link = mysql_connect(&quot;mysql_host&quot;, &quot;mysql_user&quot;, mysql_password&quot;) ‏ or die(&quot;Could not connect : &quot; . mysql_error()); echo &quot;Connected successfully&quot;; mysql_select_db(&quot;my_database&quot;) or die(&quot;Could not select database&quot;); /* Performing SQL query */ $query = &quot;SELECT * FROM my_table&quot;; $result = mysql_query($query)  or die(&quot;Query failed : &quot; . mysql_error()); /* Printing results in HTML */ echo &quot;<table>\n&quot;; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo &quot;\t<tr>\n&quot;; foreach ($line as $col_value) { echo &quot;\t\t<td>$col_value</td>\n&quot;; } echo &quot;\t</tr>\n&quot;; } echo &quot;</table>\n&quot;; Loop through each row of the result set Loop through each element in a row
Example: Looping through the Cells /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); ?>
Thank You

More Related Content

What's hot (20)

PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
Muthuselvam RS
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
Yoeung Vibol
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir20
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
Jussi Pohjolainen
 
PHP
PHPPHP
PHP
Steve Fort
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
Php mysql
Php mysqlPhp mysql
Php mysql
Abu Bakar
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
Muhamad Al Imran
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
Dhani Ahmad
 
Php Unit 1
Php Unit 1Php Unit 1
Php Unit 1
team11vgnt
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
Aminiel Michael
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
durai arasan
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
Todd Barber
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Bradley Holt
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
Deblina Chowdhury
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
Alokin Software Pvt Ltd
 

Viewers also liked (19)

Php Presentation
Php PresentationPhp Presentation
Php Presentation
Manish Bothra
 
Alphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQL
Alphorm
 
Open Source & PHP
Open Source & PHPOpen Source & PHP
Open Source & PHP
Chittaranjan Pattnaik
 
PHP - Beginner's Workshop
PHP - Beginner's WorkshopPHP - Beginner's Workshop
PHP - Beginner's Workshop
Rafael Pinto
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training Presentation
Nitesh Sharma
 
MySQL
MySQLMySQL
MySQL
Gouthaman V
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
Giuseppe Maxia
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
Guru Ji
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
Shweta A
 
Php Ppt
Php PptPhp Ppt
Php Ppt
vsnmurthy
 
Best Practices - PHP and the Oracle Database
Best Practices - PHP and the Oracle DatabaseBest Practices - PHP and the Oracle Database
Best Practices - PHP and the Oracle Database
Christopher Jones
 
Oops in PHP
Oops in PHPOops in PHP
Oops in PHP
Mindfire Solutions
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPC
Mayflower GmbH
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Dave Stokes
 
working with PHP & DB's
working with PHP & DB'sworking with PHP & DB's
working with PHP & DB's
Hi-Tech College
 
MySQLi
MySQLiMySQLi
MySQLi
Ankit Bahuguna
 
Shubhrat mishra working with php 2
Shubhrat mishra working with php 2Shubhrat mishra working with php 2
Shubhrat mishra working with php 2
Shubhrat Mishra
 
Penyederhanaan Karnaugh Map
Penyederhanaan Karnaugh MapPenyederhanaan Karnaugh Map
Penyederhanaan Karnaugh Map
Cheria Asyifa
 
Alphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQLAlphorm.com Support de la Formation PHP MySQL
Alphorm.com Support de la Formation PHP MySQL
Alphorm
 
PHP - Beginner's Workshop
PHP - Beginner's WorkshopPHP - Beginner's Workshop
PHP - Beginner's Workshop
Rafael Pinto
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training Presentation
Nitesh Sharma
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
Guru Ji
 
Introduction To PHP
Introduction To PHPIntroduction To PHP
Introduction To PHP
Shweta A
 
Best Practices - PHP and the Oracle Database
Best Practices - PHP and the Oracle DatabaseBest Practices - PHP and the Oracle Database
Best Practices - PHP and the Oracle Database
Christopher Jones
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPC
Mayflower GmbH
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Dave Stokes
 
Shubhrat mishra working with php 2
Shubhrat mishra working with php 2Shubhrat mishra working with php 2
Shubhrat mishra working with php 2
Shubhrat Mishra
 
Penyederhanaan Karnaugh Map
Penyederhanaan Karnaugh MapPenyederhanaan Karnaugh Map
Penyederhanaan Karnaugh Map
Cheria Asyifa
 
Ad

Similar to Open Source Package PHP & MySQL (20)

PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
Md. Sirajus Salayhin
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 
Web development
Web developmentWeb development
Web development
Seerat Bakhtawar
 
Php Training
Php TrainingPhp Training
Php Training
adfa
 
php basics
php basicsphp basics
php basics
NIRMAL FELIX
 
Php summary
Php summaryPhp summary
Php summary
Michelle Darling
 
IT Club @ NCP - PHP Workshop May 10, 2011
IT Club @ NCP - PHP Workshop May 10, 2011IT Club @ NCP - PHP Workshop May 10, 2011
IT Club @ NCP - PHP Workshop May 10, 2011
IT Club GTA
 
php 1
php 1php 1
php 1
tumetr1
 
Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)
Chhom Karath
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
phelios
 
PHP
PHP PHP
PHP
webhostingguy
 
Php
PhpPhp
Php
Ajaigururaj R
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
phelios
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
krutitrivedi
 
Php
PhpPhp
Php
WAHEEDA ROOHILLAH
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
banubabitha
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 
Php Training
Php TrainingPhp Training
Php Training
adfa
 
IT Club @ NCP - PHP Workshop May 10, 2011
IT Club @ NCP - PHP Workshop May 10, 2011IT Club @ NCP - PHP Workshop May 10, 2011
IT Club @ NCP - PHP Workshop May 10, 2011
IT Club GTA
 
Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)
Chhom Karath
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
phelios
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
phelios
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
krutitrivedi
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
Ad

Recently uploaded (20)

Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT PatnaSwachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Quiz Club, Indian Institute of Technology, Patna
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Pharmaceutical_Incompatibilities.pptx
Pharmaceutical_Incompatibilities.pptxPharmaceutical_Incompatibilities.pptx
Pharmaceutical_Incompatibilities.pptx
Shantanu Ranjan
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Semisolid_Dosage_Forms.pptx
Semisolid_Dosage_Forms.pptxSemisolid_Dosage_Forms.pptx
Semisolid_Dosage_Forms.pptx
Shantanu Ranjan
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATIONTHE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
THE CHURCH AND ITS IMPACT: FOSTERING CHRISTIAN EDUCATION
PROF. PAUL ALLIEU KAMARA
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Pharmaceutical_Incompatibilities.pptx
Pharmaceutical_Incompatibilities.pptxPharmaceutical_Incompatibilities.pptx
Pharmaceutical_Incompatibilities.pptx
Shantanu Ranjan
 
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in IndiaSmart Borrowing: Everything You Need to Know About Short Term Loans in India
Smart Borrowing: Everything You Need to Know About Short Term Loans in India
fincrifcontent
 
Semisolid_Dosage_Forms.pptx
Semisolid_Dosage_Forms.pptxSemisolid_Dosage_Forms.pptx
Semisolid_Dosage_Forms.pptx
Shantanu Ranjan
 

Open Source Package PHP & MySQL

  • 2. PHP Language A recursive acronym: P HP H ypertext P reprocessor A scripting language designed for creating dynamic and data-driven Web pages PHP is a server-side scripting language; it is parsed and interpreted on the server side of a Web application and the resulting output is sent to the browser. (VBScript and JavaScript are mostly client-side). Designed to work with the MySQL database system, but can also connect to other database systems.
  • 3. PHP Language PHP and MySQL are open-source; they can be obtained free-of-charge and the source codes are available for development. www.php.net www.mysql.com You will need to install PHP to work with your MS IIS or Apache Web server. PHP and MySQL are becoming increasingly popular in recent years because it is free of charge. Other software packages like Microsoft ASP.NET are expensive for small and medium enterprises.
  • 4. A Simple PHP Example <HTML> <HEAD> <TITLE>PHP Example</TITLE> </HEAD> <BODY> <? echo &quot;<b>Welcome</b>&quot;; // print the string here ?> </BODY> </HTML> PHP scripts are enclosed by the <?php And ?> tags. Can simply use <? for the opening tag. All PHP statements end with a semicolon (unless it ends the closing tag on the same line) ‏ Comments can be marked by # , // or /* */ http://147.8.210.143/php/example1.php
  • 5. Including Files You can include common files (like header, footer, and navigation bars) in PHP. <? include(&quot;header.inc&quot;) ?>
  • 6. Variables in PHP Variable names start with the dollar sign $ You can use letters and underscore for variable names. The first character after $ cannot be a number Variable names are case-sensitive For example: <? $name = &quot;Michael&quot;; ?> <? $i = 1; ?>
  • 7. Variables in PHP The three main types of variables in PHP: Scalar Array Object Scalar can be Integer, Double, Boolean, or String When you assign a value to a variable, its data type is also assigned.
  • 8. Array Arrays can be created with integers or strings as keys. <?php $arr = array(&quot;UK&quot; => &quot;London&quot;, 12 => 56); echo $arr[&quot;UK&quot;]; // London echo $arr[12];    // 56 ?>
  • 9. Object Use the class statement to define a class. Use the new statement to create an object. <?php class test {    function do_something()    {        echo &quot;Do something&quot;;    } } $my_test = new test; $my_test->do_something(); ?>
  • 10. Basic Operators Assignment/Arithmetic operators = + - * / % ++ -- += -= *= /= Comparison operators == (equal value) ‏ === (identical value and data type) ‏ != or <> < > <= >= Logical operators ! && ||
  • 11. String Concatenation Same as Perl . concatenate strings .= concatenate and assign Example: $word1 = &quot;Play&quot;; $full_string = $word1 . &quot;Station&quot;;
  • 12. String Functions There are a lot of string functions in PHP that you can use. For example: int strlen(string str) ‏ string strtoupper(string str) ‏ string strtolower(string str) ‏ int strcmp(string str1, string str2) ‏ int strcasecmp(string str1, string str2) ‏ string strstr(string src, string target) ‏ int strpos(string src, string target [, int offset]) ‏ You can find them in the PHP manual: http://www.php.net/manual/en/
  • 13. Conditions boolean variable: TRUE(1) or FALSE(0) ‏ if (EXPR) { STATEMENTS; } elseif (EXPR) { STATEMENTS; } else { STATEMENTS; } switch-case
  • 14. Loops while ( EXPR ) { STATEMENTS; } do { STATEMENTS; } while (EXPR); for ( INIT_EXPR; COND_EXPR; LOOP_EXPR ) { STATEMENTS; } foreach (ARRAY as VARIABLE) { STATEMENTS; } break, continue
  • 15. Alternative Syntax It is possible to write control statements and loops using the following “colon” format: <?php if ($a == 5): echo &quot;A is equal to 5&quot;; endif; ?>
  • 16. User-defined Functions Functions can be defined using the function keyword. <?php function function_name($arg_1, $arg_2, ...) {    statements;    return $some_value; // optional } ?>
  • 17. Mixing HTML and PHP Codes PHP codes can be easily inserted anywhere in an HTML page. You can even mix the codes together, usually to avoid writing too many “echo” statements with escape characters. <? if ($i == 1) { ?> <h2>The condition is true</h2> <center><b>$i is 1</b></center> <? } else { ?> <h2>The condition is false</h2> <center><b>$i is not 1</b></center> <? } ?> HTML PHP
  • 18. Shortcut for Writing Echos Instead of writing <? echo expression ?> You can use the following shortcut <?= expression ?> This is useful for inserting expressions and variables quickly into HTML pages.
  • 19. Working with HTML Forms You can easily get the variables submitted by an HTML form using the following (assume the form input is called “name”: $_POST['name'] // post method $_GET['name'] // get method $name /* easier, but Register Globals must be set to ON in PHP config */
  • 20. Working with HTML Forms It is common to put the form and the results of different requests in the same file. <HTML> <HEAD><TITLE>PHP FORM TEST</TITLE></HEAD> <BODY> <? if (!isset($name) || $name == &quot;&quot;) { ?> <FORM METHOD=&quot;post&quot;> Your name: <INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot;> Your age: <INPUT TYPE=&quot;text&quot; NAME=&quot;age&quot;> <INPUT TYPE=&quot;submit&quot;> </FORM> <? } else { echo &quot;Your name is $name<BR>&quot;; echo &quot;Your age is $age&quot;; } ?> </BODY> </HTML> If name is empty or not defined, then show the form If name is not empty, i.e., when the user has entered something, then show the results http://localhost/php/example2.php
  • 21. PHP and MySQL PHP is designed to work with the MySQL database. However, it can also connect to other database systems such as Oracle, Sybase, etc., using ODBC.
  • 22. Example <HTML> <BODY> <?php $db = mysql_connect(&quot;localhost&quot;, &quot;root“,””); mysql_select_db(&quot;mydb &quot; , $db); $result = mysql_query(&quot;SELECT * FROM employees&quot;,$db); printf(&quot;First Name: %s<br>\n&quot;, mysql_result($result,0,&quot;first&quot;)); printf(&quot;Last Name: %s<br>\n&quot;, mysql_result($result,0,&quot;last&quot;)); printf(&quot;Address: %s<br>\n&quot;, mysql_result($result,0,&quot;address&quot;)); printf(&quot;Position: %s<br>\n&quot;,mysql_result($result,0,&quot;position&quot;)); mysql_free_result($result); mysql_close($db); ?> </BODY> </HTML>
  • 23. Useful PHP Functions for MySQL mysql_connect(host, username [,password]); Connects to a MySQL server on the specified host using the given username and/or password. Returns a MySQL link identifier on success, or FALSE on failure. mysql_select_db(db_name [,resource]) ‏ Selects a database from the database server.
  • 24. Useful PHP Functions for MySQL mysql_query(SQL, resource); Sends the specified SQL query to the database specified by the resource identifier. The retrieved data are returned by the function as a MySQL result set. mysql_result(result, row [,field]); Returns the contents of one cell from a MySQL result set. The field argument can be the field name or the field’s offset. mysql_fetch_array(result [,result_type]) ‏ Fetch a result row as an associative array, a numeric array, or both. The result type can take the constants MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH.
  • 25. Useful PHP Functions for MySQL mysql_free_result(result) ‏ Frees the result set mysql_close(resource) ‏ Closes the connection to the database.
  • 26. Error Handling If there is error in the database connection, you can terminate the current script by using the die function. For example: $db = mysql_connect(&quot;localhost&quot;, &quot;root“, “”) or die(&quot;Could not connect : &quot; . mysql_error()); mysql_select_db(&quot;my_database&quot;) or die(&quot;Could not select database&quot;); $result = mysql_query($query) or die(&quot;Query failed&quot;);
  • 27. Example: Looping through the Cells <?php /* Connecting, selecting database */ $link = mysql_connect(&quot;mysql_host&quot;, &quot;mysql_user&quot;, mysql_password&quot;) ‏ or die(&quot;Could not connect : &quot; . mysql_error()); echo &quot;Connected successfully&quot;; mysql_select_db(&quot;my_database&quot;) or die(&quot;Could not select database&quot;); /* Performing SQL query */ $query = &quot;SELECT * FROM my_table&quot;; $result = mysql_query($query) or die(&quot;Query failed : &quot; . mysql_error()); /* Printing results in HTML */ echo &quot;<table>\n&quot;; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo &quot;\t<tr>\n&quot;; foreach ($line as $col_value) { echo &quot;\t\t<td>$col_value</td>\n&quot;; } echo &quot;\t</tr>\n&quot;; } echo &quot;</table>\n&quot;; Loop through each row of the result set Loop through each element in a row
  • 28. Example: Looping through the Cells /* Free resultset */ mysql_free_result($result); /* Closing connection */ mysql_close($link); ?>