SlideShare a Scribd company logo
PHP A scripting language design to produce HTML pages
PHP Introduction PHP serves the same purpose as Java Server Pages (JSP) and Active Server Pages (ASP) All are server-side languages “parsed” by a web server Script execution results are sent to a browser as an HTML page PHP is a type-less language
PHP Structure Tradition: Start with an HTML file Add special tags to separate PHP code from HTML statements Web server parses the PHP file, producing HTML Now can be used to output XML, image, PDF, just by setting content-type
Example: myfirst.php <html> <body> <?php //A comment /*Or comment like this*/ print(&quot;<b>Hello world</b>&quot;); $v = 5; print(&quot;<p>Hello again &quot; . $v ); print(&quot;<p>Hello a third time $v&quot;); ?> </body> </html>
Variables All variables start with a dollar sign,  $ $u = 5; $v = “hello”; $w = 1.22; $x = $u + $v;  //arithmetic with + - ONLY $y = $v . $v;  //concatenation with period operator $x =  $u . $u;  //produces 55, not 10
Printing $u = 5; print( “5 hello” );  //print anything in quotes print( $u . “hello” );  //prints 5hello print( “$u Hello” );  //prints 5 Hello
String-Related Functions $v = “hello”; strlen( $v);  //returns 5 trim( $v);  //trims any spaces on either side of a string $x = strtolower ($v);  //$x has hello $x = strtoupper($v);  //$x has HELLO $str = “abcdef”; $a = substr( $str, 3, 3 ); # of characters to copy Start position, zero indexed Source string “ def” Can be negative to start from right side
Getting HTML Form Data There are 3 ways to get form data in PHP Global variables – this is a bad way because of security problems. PHP creates a variable with a name matching the form field name in the source HTML. POST variable associative array Prior to version 4.1,  $HTTP_POST_VARS 4.1 and after,  $_POST GET variable associative array Same as POST, but use GET
Examples Global variables   (HTML has field with name ‘abc’) print ($abc); POST  print($_POST(‘abc’));  //4.1 and after GET print($_GET(‘abc’));  //4.1 and after
Comparing Strings strcmp( $a, $b );  //works like C function Returns:  – 1 if first string less than second string   0 if the same 1 if first string greater than second string It is case sensitive
PHP Syntax Similarities Has a switch statement for  loop is the same, but uses PHP variable syntax for ($i=0; $i < 10; $i++ ){  ….  } while  and  if  are also what you’d expect Standard logical operators: ==, &&, <, > …
Other Useful Functions round ($a);  //rounds a number is_numeric($v);  //returns true/false rand($start, $end);  //Produces int rand
Current Date/Time Use date function to get the current date. Takes a format string to provide the date in a format you want. See  http://php.net/date . Use time function to get the current time. Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
Creating Functions function myfunc( $a, $b, $c ) { //this is my code return $x; }
External PHP Files Can use  require  or  include Require will produce a fatal error if the file cannot be found Include will just ignore a missing script file require(‘my.php’); include(‘my.php’); The files can contain PHP and/or HTML
Arrays Creating an array $a = array(1,2,3,4,5); Accessing array elements $v = $a[2]; $a[2] = 5; $a[] = 1; $a[] = 2; $a[] = 3;  //appends to array
Iterating Over Arrays for ($i=0; $i<count($a); $i++ ) { print ($a[i]); } foreach( $a as $item ) { print( “<p>$item”); } Array variable Local variable. Set to next array element each iteration.
Other Array Functions $m = max($a);  //returns max value in array $m = min($a);  //returns min value in array $s = array_sum($a); //returns sum or array values sort($a);  //sorts the items in the array. Changes //the array itself Optional second argument is “sort flags” to control the sort.
Associative Arrays Arrays containing key/value pairs $s = array( ‘a’=>’alpha’, ‘b’=>’beta’, … ); print ( $s[‘b’] ); The parameter to the left of => is the key. The right parameter is the value.
SQL – Structured Query Language A language for accessing relational databases Relational databases have tables Tables have fields and contain rows of data
SQL Syntax – SELECT Used for retrieving data from a database SELECT [fields] FROM [tables] WHERE [expr] Examples select * from users select abc, def from mytable where ghi=5
SQL Syntax – INSERT Used to insert new data in a table INSERT INTO [table] [field names] VALUES [values] Examples insert into users (abc,def,ghi) values (‘111’,22,’cc) insert into xyz values (1,2,3,4,5)
SQL Syntax – UPDATE Updating one or more values in existing rows in a table UPDATE [table] SET [name=value pairs] WHERE [expression] Examples update mytable set a=‘aaa’, b=55 where c=11
PHP and Mysql Database 5 steps Connect to the Mysql DBMS Pick a database Execute an SQL statement If the SQL was a ‘select’, retrieve the data Close the connection
Connecting to Mysql DBMS $con = mysql_connect(  /* 3 arguments */ ); Your Mysql DBMS server process network location Your Mysql user ID Your Mysql user password For tonight only, mysql_connect(‘www.freesql.org’,’upeworkshop’,’upeworkshop’);
Selecting a Database mysql_select_db( ‘upeworkshop’ );
Executing an SQL Statement mysql_query( /*SQL statement*/ ); Proper form for any SQL not a Select if ( !mysql_query ( “update a ….” ); ) { echo mysql_error(); //for easy debugging, not for final user-oriented website }  //returns true/false if it worked, or not
For Select SQL Statements $r = mysql_query( ‘select * from abc’ ); while ( $row = mysql_fetch_row( $r ) ) {  …  } $row contains a row of data returns false when no more rows available Iterating through the fields in the row foreach ( $row as $item ) { … } OR access the fields using index position (zero indexed) OR put results in an associative array – less error prone while ($row = mysql_fetch_assoc($r)){ echo $row[‘firstname’]; }
Closing a Connection mysql_close( $con );

More Related Content

What's hot (20)

php
phpphp
php
ajeetjhajharia
 
Php mysql
Php mysqlPhp mysql
Php mysql
Shehrevar Davierwala
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
Eyal Vardi
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Php basics
Php basicsPhp basics
Php basics
Jamshid Hashimi
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
Hamid Ghorbani
 
PHP
PHPPHP
PHP
sometech
 
Spring boot
Spring bootSpring boot
Spring boot
Pradeep Shanmugam
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
CPD INDIA
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
Best PHP Frameworks
Best PHP FrameworksBest PHP Frameworks
Best PHP Frameworks
Clixlogix Technologies
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Christian Schneider
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
Mayank Panchal
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
JIGAR MAKHIJA
 
PHP para Adultos: Clean Code e Object Calisthenics
PHP para Adultos: Clean Code e Object CalisthenicsPHP para Adultos: Clean Code e Object Calisthenics
PHP para Adultos: Clean Code e Object Calisthenics
Guilherme Blanco
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
asif290119
 
PHP slides
PHP slidesPHP slides
PHP slides
Farzad Wadia
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
Manish Bothra
 

Viewers also liked (7)

PHP Workshop at ISCTE-IUL Mar 2015
PHP Workshop at ISCTE-IUL Mar 2015PHP Workshop at ISCTE-IUL Mar 2015
PHP Workshop at ISCTE-IUL Mar 2015
André Aleixo
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
durai arasan
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
Ghaffar Khan
 
Oops ppt
Oops pptOops ppt
Oops ppt
abhayjuneja
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
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
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
PHP Workshop at ISCTE-IUL Mar 2015
PHP Workshop at ISCTE-IUL Mar 2015PHP Workshop at ISCTE-IUL Mar 2015
PHP Workshop at ISCTE-IUL Mar 2015
André Aleixo
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
durai arasan
 
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
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Ad

Similar to PHP Workshop Notes (20)

PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
Md. Sirajus Salayhin
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir20
 
Php course-in-navimumbai
Php course-in-navimumbaiPhp course-in-navimumbai
Php course-in-navimumbai
vibrantuser
 
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptxPHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
 
php AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdfphp AND MYSQL _ppt.pdf
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
Vibrant Technologies & Computers
 
PHP
PHP PHP
PHP
webhostingguy
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
Norhisyam Dasuki
 
Php introduction
Php introductionPhp introduction
Php introduction
Osama Ghandour Geris
 
Quick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHPQuick beginner to Lower-Advanced guide/tutorial in PHP
Quick beginner to Lower-Advanced guide/tutorial in PHP
Sanju Sony Kurian
 
Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHP
webhostingguy
 
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
 
Ch1(introduction to php)
Ch1(introduction to php)Ch1(introduction to php)
Ch1(introduction to php)
Chhom Karath
 
Ad

More from Pamela Fox (20)

Teaching Programming Online
Teaching Programming OnlineTeaching Programming Online
Teaching Programming Online
Pamela Fox
 
Engineering culture
Engineering cultureEngineering culture
Engineering culture
Pamela Fox
 
Django Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryDjango Admin: Widgetry & Witchery
Django Admin: Widgetry & Witchery
Pamela Fox
 
A Year of Hermit Hacking
A Year of Hermit HackingA Year of Hermit Hacking
A Year of Hermit Hacking
Pamela Fox
 
The Developer Experience
The Developer Experience The Developer Experience
The Developer Experience
Pamela Fox
 
Making JavaScript Libraries More Approachable
Making JavaScript Libraries More ApproachableMaking JavaScript Libraries More Approachable
Making JavaScript Libraries More Approachable
Pamela Fox
 
How I became a born again vegetable-tarian
How I became a born again vegetable-tarianHow I became a born again vegetable-tarian
How I became a born again vegetable-tarian
Pamela Fox
 
The Developer Experience
The Developer ExperienceThe Developer Experience
The Developer Experience
Pamela Fox
 
No, Really, I'm Shy
No, Really, I'm ShyNo, Really, I'm Shy
No, Really, I'm Shy
Pamela Fox
 
Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)
Pamela Fox
 
Writing Apps the Google-y Way
Writing Apps the Google-y WayWriting Apps the Google-y Way
Writing Apps the Google-y Way
Pamela Fox
 
The Wonders of the "Onesie"
The Wonders of the "Onesie"The Wonders of the "Onesie"
The Wonders of the "Onesie"
Pamela Fox
 
I’M A Barbie Girl In A CS World
I’M A Barbie Girl In A CS WorldI’M A Barbie Girl In A CS World
I’M A Barbie Girl In A CS World
Pamela Fox
 
Google Wave 20/20: Product, Protocol, Platform
Google Wave 20/20: Product, Protocol, PlatformGoogle Wave 20/20: Product, Protocol, Platform
Google Wave 20/20: Product, Protocol, Platform
Pamela Fox
 
Collaborative Mapping with Google Wave
Collaborative Mapping with Google WaveCollaborative Mapping with Google Wave
Collaborative Mapping with Google Wave
Pamela Fox
 
Google Products: Deep Dive on Google Maps
Google Products: Deep Dive on Google MapsGoogle Products: Deep Dive on Google Maps
Google Products: Deep Dive on Google Maps
Pamela Fox
 
Google Products & Google Maps
Google Products & Google MapsGoogle Products & Google Maps
Google Products & Google Maps
Pamela Fox
 
Mashups & APIs
Mashups & APIsMashups & APIs
Mashups & APIs
Pamela Fox
 
A World of Words
A World of WordsA World of Words
A World of Words
Pamela Fox
 
Web APIs & Google APIs
Web APIs & Google APIsWeb APIs & Google APIs
Web APIs & Google APIs
Pamela Fox
 
Teaching Programming Online
Teaching Programming OnlineTeaching Programming Online
Teaching Programming Online
Pamela Fox
 
Engineering culture
Engineering cultureEngineering culture
Engineering culture
Pamela Fox
 
Django Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryDjango Admin: Widgetry & Witchery
Django Admin: Widgetry & Witchery
Pamela Fox
 
A Year of Hermit Hacking
A Year of Hermit HackingA Year of Hermit Hacking
A Year of Hermit Hacking
Pamela Fox
 
The Developer Experience
The Developer Experience The Developer Experience
The Developer Experience
Pamela Fox
 
Making JavaScript Libraries More Approachable
Making JavaScript Libraries More ApproachableMaking JavaScript Libraries More Approachable
Making JavaScript Libraries More Approachable
Pamela Fox
 
How I became a born again vegetable-tarian
How I became a born again vegetable-tarianHow I became a born again vegetable-tarian
How I became a born again vegetable-tarian
Pamela Fox
 
The Developer Experience
The Developer ExperienceThe Developer Experience
The Developer Experience
Pamela Fox
 
No, Really, I'm Shy
No, Really, I'm ShyNo, Really, I'm Shy
No, Really, I'm Shy
Pamela Fox
 
Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)
Pamela Fox
 
Writing Apps the Google-y Way
Writing Apps the Google-y WayWriting Apps the Google-y Way
Writing Apps the Google-y Way
Pamela Fox
 
The Wonders of the "Onesie"
The Wonders of the "Onesie"The Wonders of the "Onesie"
The Wonders of the "Onesie"
Pamela Fox
 
I’M A Barbie Girl In A CS World
I’M A Barbie Girl In A CS WorldI’M A Barbie Girl In A CS World
I’M A Barbie Girl In A CS World
Pamela Fox
 
Google Wave 20/20: Product, Protocol, Platform
Google Wave 20/20: Product, Protocol, PlatformGoogle Wave 20/20: Product, Protocol, Platform
Google Wave 20/20: Product, Protocol, Platform
Pamela Fox
 
Collaborative Mapping with Google Wave
Collaborative Mapping with Google WaveCollaborative Mapping with Google Wave
Collaborative Mapping with Google Wave
Pamela Fox
 
Google Products: Deep Dive on Google Maps
Google Products: Deep Dive on Google MapsGoogle Products: Deep Dive on Google Maps
Google Products: Deep Dive on Google Maps
Pamela Fox
 
Google Products & Google Maps
Google Products & Google MapsGoogle Products & Google Maps
Google Products & Google Maps
Pamela Fox
 
Mashups & APIs
Mashups & APIsMashups & APIs
Mashups & APIs
Pamela Fox
 
A World of Words
A World of WordsA World of Words
A World of Words
Pamela Fox
 
Web APIs & Google APIs
Web APIs & Google APIsWeb APIs & Google APIs
Web APIs & Google APIs
Pamela Fox
 

Recently uploaded (20)

Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 

PHP Workshop Notes

  • 1. PHP A scripting language design to produce HTML pages
  • 2. PHP Introduction PHP serves the same purpose as Java Server Pages (JSP) and Active Server Pages (ASP) All are server-side languages “parsed” by a web server Script execution results are sent to a browser as an HTML page PHP is a type-less language
  • 3. PHP Structure Tradition: Start with an HTML file Add special tags to separate PHP code from HTML statements Web server parses the PHP file, producing HTML Now can be used to output XML, image, PDF, just by setting content-type
  • 4. Example: myfirst.php <html> <body> <?php //A comment /*Or comment like this*/ print(&quot;<b>Hello world</b>&quot;); $v = 5; print(&quot;<p>Hello again &quot; . $v ); print(&quot;<p>Hello a third time $v&quot;); ?> </body> </html>
  • 5. Variables All variables start with a dollar sign, $ $u = 5; $v = “hello”; $w = 1.22; $x = $u + $v; //arithmetic with + - ONLY $y = $v . $v; //concatenation with period operator $x = $u . $u; //produces 55, not 10
  • 6. Printing $u = 5; print( “5 hello” ); //print anything in quotes print( $u . “hello” ); //prints 5hello print( “$u Hello” ); //prints 5 Hello
  • 7. String-Related Functions $v = “hello”; strlen( $v); //returns 5 trim( $v); //trims any spaces on either side of a string $x = strtolower ($v); //$x has hello $x = strtoupper($v); //$x has HELLO $str = “abcdef”; $a = substr( $str, 3, 3 ); # of characters to copy Start position, zero indexed Source string “ def” Can be negative to start from right side
  • 8. Getting HTML Form Data There are 3 ways to get form data in PHP Global variables – this is a bad way because of security problems. PHP creates a variable with a name matching the form field name in the source HTML. POST variable associative array Prior to version 4.1, $HTTP_POST_VARS 4.1 and after, $_POST GET variable associative array Same as POST, but use GET
  • 9. Examples Global variables (HTML has field with name ‘abc’) print ($abc); POST print($_POST(‘abc’)); //4.1 and after GET print($_GET(‘abc’)); //4.1 and after
  • 10. Comparing Strings strcmp( $a, $b ); //works like C function Returns: – 1 if first string less than second string 0 if the same 1 if first string greater than second string It is case sensitive
  • 11. PHP Syntax Similarities Has a switch statement for loop is the same, but uses PHP variable syntax for ($i=0; $i < 10; $i++ ){ …. } while and if are also what you’d expect Standard logical operators: ==, &&, <, > …
  • 12. Other Useful Functions round ($a); //rounds a number is_numeric($v); //returns true/false rand($start, $end); //Produces int rand
  • 13. Current Date/Time Use date function to get the current date. Takes a format string to provide the date in a format you want. See http://php.net/date . Use time function to get the current time. Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
  • 14. Creating Functions function myfunc( $a, $b, $c ) { //this is my code return $x; }
  • 15. External PHP Files Can use require or include Require will produce a fatal error if the file cannot be found Include will just ignore a missing script file require(‘my.php’); include(‘my.php’); The files can contain PHP and/or HTML
  • 16. Arrays Creating an array $a = array(1,2,3,4,5); Accessing array elements $v = $a[2]; $a[2] = 5; $a[] = 1; $a[] = 2; $a[] = 3; //appends to array
  • 17. Iterating Over Arrays for ($i=0; $i<count($a); $i++ ) { print ($a[i]); } foreach( $a as $item ) { print( “<p>$item”); } Array variable Local variable. Set to next array element each iteration.
  • 18. Other Array Functions $m = max($a); //returns max value in array $m = min($a); //returns min value in array $s = array_sum($a); //returns sum or array values sort($a); //sorts the items in the array. Changes //the array itself Optional second argument is “sort flags” to control the sort.
  • 19. Associative Arrays Arrays containing key/value pairs $s = array( ‘a’=>’alpha’, ‘b’=>’beta’, … ); print ( $s[‘b’] ); The parameter to the left of => is the key. The right parameter is the value.
  • 20. SQL – Structured Query Language A language for accessing relational databases Relational databases have tables Tables have fields and contain rows of data
  • 21. SQL Syntax – SELECT Used for retrieving data from a database SELECT [fields] FROM [tables] WHERE [expr] Examples select * from users select abc, def from mytable where ghi=5
  • 22. SQL Syntax – INSERT Used to insert new data in a table INSERT INTO [table] [field names] VALUES [values] Examples insert into users (abc,def,ghi) values (‘111’,22,’cc) insert into xyz values (1,2,3,4,5)
  • 23. SQL Syntax – UPDATE Updating one or more values in existing rows in a table UPDATE [table] SET [name=value pairs] WHERE [expression] Examples update mytable set a=‘aaa’, b=55 where c=11
  • 24. PHP and Mysql Database 5 steps Connect to the Mysql DBMS Pick a database Execute an SQL statement If the SQL was a ‘select’, retrieve the data Close the connection
  • 25. Connecting to Mysql DBMS $con = mysql_connect( /* 3 arguments */ ); Your Mysql DBMS server process network location Your Mysql user ID Your Mysql user password For tonight only, mysql_connect(‘www.freesql.org’,’upeworkshop’,’upeworkshop’);
  • 26. Selecting a Database mysql_select_db( ‘upeworkshop’ );
  • 27. Executing an SQL Statement mysql_query( /*SQL statement*/ ); Proper form for any SQL not a Select if ( !mysql_query ( “update a ….” ); ) { echo mysql_error(); //for easy debugging, not for final user-oriented website } //returns true/false if it worked, or not
  • 28. For Select SQL Statements $r = mysql_query( ‘select * from abc’ ); while ( $row = mysql_fetch_row( $r ) ) { … } $row contains a row of data returns false when no more rows available Iterating through the fields in the row foreach ( $row as $item ) { … } OR access the fields using index position (zero indexed) OR put results in an associative array – less error prone while ($row = mysql_fetch_assoc($r)){ echo $row[‘firstname’]; }
  • 29. Closing a Connection mysql_close( $con );