SlideShare a Scribd company logo
>_ Things Lab
PHP
http://www.thingslab.cc
How to start with PHP?
Check the slides of the previous presentation:
http://www.slideshare.net/thingslab/php-programming-intro
If you need help ask to the staff
Summary of some useful unix commands:
sudo apt-get install package-name
sudo apt-cache search php- |more
sudo service apache2 restart
Enable the PHP Error Reporting
In the terminal, execute:
cd /etc/php5/apache2 ; sudo leafpad php.ini &
Search and remove the comment instruction ; from
display_errors
Default Value: On
Development Value: On
Production Value: On
error_reporting
Default Value: E_ALL & ~E_NOTICE
Development Value: E_ALL | E_STRICT
Production Value: E_ALL & ~E_DEPRECATED
Test a code with errors
Restart apache from command line:
sudo service apache2 restart
Execute the following code:
<?php
print "error in the next line! What is it wrong?"; // after remove
parint "aaa"; // after remove
print phpinfo(); // dump all the info of the Apache and PHP
?>
The error reporting can be very useful for
debugging and for PHP beginners
Install PHP My Admin
Install Mysql Server, Mysql Client, PHP Mysql
module and PHP My Admin:
sudo apt-get install mysql-server-5.1 php5-mysql phpmyadmin
Create an user and add specific permissions to
the user, after create a database and add the the
following tables:
users
books
comments
Users
Table: Users
Fields:
id as integer, auto increment, primary ke
login as string of 50 characters, index
password as string of 50 characters
role as string of 10 characters
Books
Table: Books
Fields:
id as integer, auto increment, primary ke
title as string of 50 characters, index
description as text
pages as integer
Add as many field you like to test the different
type of data
Comments
Table: Comments
Fields:
id as integer, auto increment, primary ke
user_id as integer, index
book_id as integer, index
comments as text
Add as many field you like to test the different
type of data
Populate the database
Populate the tables in the database with at least
5 records each.
The following conditions should be followed:
● Table users with one user that has id = 10
● Table books with one book that has id = 50
● Table comments with one comment where the book_id = 50
and user_id = 10
We will play in the next slide using some
advanced SQL queries (Join queries).
http://dev.mysql.com/doc/ Use the right version!
HOWTO SQL Joins
Open the PHP Manual
Open the main reference for PHP:
sudo apt-get install mysql-server-5.1 php5-mysql phpmyadmin
Search for mysqli section or open:
http://php.net/manual/en/book.mysqli.php
Check in the manual the following commands:
mysqli_connect
$resource->query ($resource is the connection to the database)
mysqli_fetch_array
mysqli_prepare
mysqli_stmt_bind_param
mysqli_stmt_execute
mysqli_stmt_get_result
mysqli_close
Search in the database (users)
//connection: adapt the login/password/database name
$link = mysqli_connect("localhost","root","password","test") or
die("Error " . mysqli_error($link));
//consultation:
$query = "SELECT * FROM users WHERE user_id <> 10" or
die("Error in the consult." . mysqli_error($link));
//execute the query.
$result = $link->query($query);
//display information:
while($row = mysqli_fetch_array($result)) {
echo $row["name"] . "<br>";
}
mysqli_close($link);
Insert a value in the database
$a = $_GET["a"];
if (isset($a)) {
// is in one line!
$link = mysqli_connect("localhost","root","password","test") or
die("Error " . mysqli_error($link));
print $a;
$query = "insert into users (name, password) values ('$a', 'abc')";
$result = $link->query($query);
mysqli_close($link);
} else {
print "No variable "a" passed to the program <BR>";
print "user the following syntax filename.php?a=200";
}
Execute a statement
$query = "INSERT INTO books (login, password) VALUES
(?,?)"; /* Prepare an insert statement */
$stmt = $mysqli->prepare($query);
$stmt->bind_param("sss", $val1, $val2);
$val1 = 'login-1';
$val2 = 'password-1';
$stmt->execute(); /* Execute the statement */
// another statement executed
$val1 = 'login-2'; $val2 = 'password-2'; $stmt->execute();
/* close statement */
$stmt->close();
Create a link in HTML
We can link different pages as this example:
<A HREF=”display.php?id=100”>Book title</A>
In PHP can be used as:
$id = 100;
$title = “This is my book”;
print “<A HREF=”display.php?id=$id”>$title</A>”;
What's next?
Propose us which subjects you want to explore,
some examples can be :
- Advanced PHP/HTML
- PHP and Javascript
- DEVOPS in practice
- A real software developed in team using githu?
e.g. Smart Farms
Exercises

Link the page where you display the results to a
new page were you display the values of a single
record
Display a page with all the comments of one
specific book. The exercise can be performed
using one or two SQL queries, in our case we
want to use a single SQL join (decide which one
you want to use).
Exercises
Delete a record in PHP using a parameter from
HTML
Update a table with some parameter received
from the browser (HTML) and test the different
type of data (e.g. integer, string, data, etc.)
Install and use an example of the PDF module of
PHP based on the previous slides (also use the
slides of the previous workshops)

More Related Content

What's hot (20)

Codeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework ComponentsCodeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework Components
Abdul Malik Ikhsan
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 
Check username availability with vue.js and PHP
Check username availability with vue.js and PHPCheck username availability with vue.js and PHP
Check username availability with vue.js and PHP
Yogesh singh
 
New: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPNew: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPP
Rupesh Kumar
 
Php session 3 Important topics
Php session 3 Important topicsPhp session 3 Important topics
Php session 3 Important topics
mohamedsaad24
 
Add loop shortcode
Add loop shortcodeAdd loop shortcode
Add loop shortcode
Peter Baylies
 
M.php
M.phpM.php
M.php
SanderZHackedOwn
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Bradley Holt
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
brian d foy
 
Client-side Storage 
Client-side Storage Client-side Storage 
Client-side Storage 
T W
 
Sah
SahSah
Sah
sahul azzez m.i
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
Php - Getting good with session
Php - Getting good with sessionPhp - Getting good with session
Php - Getting good with session
Firdaus Adib
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
herat university
 
Simple php backdoor_by_dk
Simple php backdoor_by_dkSimple php backdoor_by_dk
Simple php backdoor_by_dk
Stan Adrian
 
Php
PhpPhp
Php
supriya pandit
 
Pemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan SessionPemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan Session
Nur Fadli Utomo
 
Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1
beckman16
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
Subhasis Nayak
 
Installing odoo v8 from github
Installing odoo v8 from githubInstalling odoo v8 from github
Installing odoo v8 from github
Antony Gitomeh
 
Codeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework ComponentsCodeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework Components
Abdul Malik Ikhsan
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 
Check username availability with vue.js and PHP
Check username availability with vue.js and PHPCheck username availability with vue.js and PHP
Check username availability with vue.js and PHP
Yogesh singh
 
New: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPPNew: Two Methods of Installing Drupal on Windows XP with XAMPP
New: Two Methods of Installing Drupal on Windows XP with XAMPP
Rupesh Kumar
 
Php session 3 Important topics
Php session 3 Important topicsPhp session 3 Important topics
Php session 3 Important topics
mohamedsaad24
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Bradley Holt
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
brian d foy
 
Client-side Storage 
Client-side Storage Client-side Storage 
Client-side Storage 
T W
 
Php - Getting good with session
Php - Getting good with sessionPhp - Getting good with session
Php - Getting good with session
Firdaus Adib
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
herat university
 
Simple php backdoor_by_dk
Simple php backdoor_by_dkSimple php backdoor_by_dk
Simple php backdoor_by_dk
Stan Adrian
 
Pemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan SessionPemrograman Web 9 - Input Form DB dan Session
Pemrograman Web 9 - Input Form DB dan Session
Nur Fadli Utomo
 
Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1
beckman16
 
Installing odoo v8 from github
Installing odoo v8 from githubInstalling odoo v8 from github
Installing odoo v8 from github
Antony Gitomeh
 

Viewers also liked (17)

Temperature Sensor Thermocouple and RTD
Temperature Sensor Thermocouple and RTDTemperature Sensor Thermocouple and RTD
Temperature Sensor Thermocouple and RTD
rashid09
 
(Not so) big data with Chart.js
(Not so) big data with Chart.js(Not so) big data with Chart.js
(Not so) big data with Chart.js
Things Lab
 
Things lab - introduction to programming
Things lab - introduction to programmingThings lab - introduction to programming
Things lab - introduction to programming
Things Lab
 
The Matrimonial Strategist,
The Matrimonial Strategist,The Matrimonial Strategist,
The Matrimonial Strategist,
Thomas Mastromatto NMLS #145824
 
Introduction to HireIQ Solutions
Introduction to HireIQ SolutionsIntroduction to HireIQ Solutions
Introduction to HireIQ Solutions
HireIQ Solutions, Inc.
 
RateMyClothes application
RateMyClothes applicationRateMyClothes application
RateMyClothes application
sullivan113
 
Banking Services
Banking ServicesBanking Services
Banking Services
Kapil Kateja
 
5 Tips To Help You Experience A Breakthrough In Your Singing by Esther Wilds
5 Tips To Help You Experience A Breakthrough In Your Singing by Esther Wilds5 Tips To Help You Experience A Breakthrough In Your Singing by Esther Wilds
5 Tips To Help You Experience A Breakthrough In Your Singing by Esther Wilds
delightfulinjur38
 
Samsung galaxy s6
Samsung galaxy s6Samsung galaxy s6
Samsung galaxy s6
Kukuh Malindo
 
Divorce Budget Worksheet
Divorce Budget WorksheetDivorce Budget Worksheet
Divorce Budget Worksheet
Thomas Mastromatto NMLS #145824
 
Workforce Analysis and Education Alignment Strategy
Workforce Analysis and Education Alignment StrategyWorkforce Analysis and Education Alignment Strategy
Workforce Analysis and Education Alignment Strategy
oiiannie
 
Visualizing Built Environments and Injury in Low Resource Settings
Visualizing Built Environments and Injury in Low Resource SettingsVisualizing Built Environments and Injury in Low Resource Settings
Visualizing Built Environments and Injury in Low Resource Settings
Independent Consultant | Research, data, tech policy
 
ปลุกจิตคณิต ม.4 - ฟังก์ชั่น
ปลุกจิตคณิต ม.4 - ฟังก์ชั่นปลุกจิตคณิต ม.4 - ฟังก์ชั่น
ปลุกจิตคณิต ม.4 - ฟังก์ชั่น
photmathawee
 
Senior Life PDF
Senior Life PDFSenior Life PDF
Senior Life PDF
Sam Ayerst
 
Question 7
Question 7Question 7
Question 7
Tia Courtney Constant
 
Dhruvit.ppt
Dhruvit.pptDhruvit.ppt
Dhruvit.ppt
Dhruvit Kukadiya
 
Question 6
Question 6Question 6
Question 6
Tia Courtney Constant
 
Temperature Sensor Thermocouple and RTD
Temperature Sensor Thermocouple and RTDTemperature Sensor Thermocouple and RTD
Temperature Sensor Thermocouple and RTD
rashid09
 
(Not so) big data with Chart.js
(Not so) big data with Chart.js(Not so) big data with Chart.js
(Not so) big data with Chart.js
Things Lab
 
Things lab - introduction to programming
Things lab - introduction to programmingThings lab - introduction to programming
Things lab - introduction to programming
Things Lab
 
RateMyClothes application
RateMyClothes applicationRateMyClothes application
RateMyClothes application
sullivan113
 
5 Tips To Help You Experience A Breakthrough In Your Singing by Esther Wilds
5 Tips To Help You Experience A Breakthrough In Your Singing by Esther Wilds5 Tips To Help You Experience A Breakthrough In Your Singing by Esther Wilds
5 Tips To Help You Experience A Breakthrough In Your Singing by Esther Wilds
delightfulinjur38
 
Workforce Analysis and Education Alignment Strategy
Workforce Analysis and Education Alignment StrategyWorkforce Analysis and Education Alignment Strategy
Workforce Analysis and Education Alignment Strategy
oiiannie
 
ปลุกจิตคณิต ม.4 - ฟังก์ชั่น
ปลุกจิตคณิต ม.4 - ฟังก์ชั่นปลุกจิตคณิต ม.4 - ฟังก์ชั่น
ปลุกจิตคณิต ม.4 - ฟังก์ชั่น
photmathawee
 
Senior Life PDF
Senior Life PDFSenior Life PDF
Senior Life PDF
Sam Ayerst
 
Ad

Similar to PHP and Databases (20)

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
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
Dave Stokes
 
Php summary
Php summaryPhp summary
Php summary
Michelle Darling
 
Download It
Download ItDownload It
Download It
webhostingguy
 
3-Chapter-Edit.pptx debre tabour university
3-Chapter-Edit.pptx debre tabour university3-Chapter-Edit.pptx debre tabour university
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
Php modul-3
Php modul-3Php modul-3
Php modul-3
Kristophorus Hadiono
 
Php simple
Php simplePhp simple
Php simple
PrinceGuru MS
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
webhostingguy
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
ADARSH BHATT
 
Amp and higher computing science
Amp and higher computing scienceAmp and higher computing science
Amp and higher computing science
Charlie Love
 
Php
PhpPhp
Php
Tohid Kovadiya
 
Php
PhpPhp
Php
khushbulakhani1
 
3 php-connect-to-my sql
3 php-connect-to-my sql3 php-connect-to-my sql
3 php-connect-to-my sql
Achchuthan Yogarajah
 
veracruz
veracruzveracruz
veracruz
tutorialsruby
 
veracruz
veracruzveracruz
veracruz
tutorialsruby
 
veracruz
veracruzveracruz
veracruz
tutorialsruby
 
veracruz
veracruzveracruz
veracruz
tutorialsruby
 
Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
Sumit Biswas
 
php_mysql_tutorial
php_mysql_tutorialphp_mysql_tutorial
php_mysql_tutorial
tutorialsruby
 
php_mysql_tutorial
php_mysql_tutorialphp_mysql_tutorial
php_mysql_tutorial
tutorialsruby
 
Ad

More from Things Lab (10)

3D Printer Workshop - From your idea to a real object
3D Printer Workshop - From your idea to a real object3D Printer Workshop - From your idea to a real object
3D Printer Workshop - From your idea to a real object
Things Lab
 
Things lab - Intro fritzing
Things lab - Intro fritzingThings lab - Intro fritzing
Things lab - Intro fritzing
Things Lab
 
Real world Webapp
Real world WebappReal world Webapp
Real world Webapp
Things Lab
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
Things Lab
 
Website with HTML CSS
Website with HTML CSSWebsite with HTML CSS
Website with HTML CSS
Things Lab
 
Arduino
ArduinoArduino
Arduino
Things Lab
 
Cryptanalysis - basic ciphers and a bit more
Cryptanalysis - basic ciphers and a bit moreCryptanalysis - basic ciphers and a bit more
Cryptanalysis - basic ciphers and a bit more
Things Lab
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with Git
Things Lab
 
Some hours of python
Some hours of pythonSome hours of python
Some hours of python
Things Lab
 
An Hour of Arduino and Ardublock
An Hour of Arduino and ArdublockAn Hour of Arduino and Ardublock
An Hour of Arduino and Ardublock
Things Lab
 
3D Printer Workshop - From your idea to a real object
3D Printer Workshop - From your idea to a real object3D Printer Workshop - From your idea to a real object
3D Printer Workshop - From your idea to a real object
Things Lab
 
Things lab - Intro fritzing
Things lab - Intro fritzingThings lab - Intro fritzing
Things lab - Intro fritzing
Things Lab
 
Real world Webapp
Real world WebappReal world Webapp
Real world Webapp
Things Lab
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
Things Lab
 
Website with HTML CSS
Website with HTML CSSWebsite with HTML CSS
Website with HTML CSS
Things Lab
 
Cryptanalysis - basic ciphers and a bit more
Cryptanalysis - basic ciphers and a bit moreCryptanalysis - basic ciphers and a bit more
Cryptanalysis - basic ciphers and a bit more
Things Lab
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with Git
Things Lab
 
Some hours of python
Some hours of pythonSome hours of python
Some hours of python
Things Lab
 
An Hour of Arduino and Ardublock
An Hour of Arduino and ArdublockAn Hour of Arduino and Ardublock
An Hour of Arduino and Ardublock
Things Lab
 

Recently uploaded (20)

Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Boost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for SchoolsBoost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for Schools
Visitu
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
The rise of e-commerce has redefined how retailers operate—and reconciliation...
The rise of e-commerce has redefined how retailers operate—and reconciliation...The rise of e-commerce has redefined how retailers operate—and reconciliation...
The rise of e-commerce has redefined how retailers operate—and reconciliation...
Prachi Desai
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Boost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for SchoolsBoost Student Engagement with Smart Attendance Software for Schools
Boost Student Engagement with Smart Attendance Software for Schools
Visitu
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
The rise of e-commerce has redefined how retailers operate—and reconciliation...
The rise of e-commerce has redefined how retailers operate—and reconciliation...The rise of e-commerce has redefined how retailers operate—and reconciliation...
The rise of e-commerce has redefined how retailers operate—and reconciliation...
Prachi Desai
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 

PHP and Databases

  • 2. How to start with PHP? Check the slides of the previous presentation: http://www.slideshare.net/thingslab/php-programming-intro If you need help ask to the staff Summary of some useful unix commands: sudo apt-get install package-name sudo apt-cache search php- |more sudo service apache2 restart
  • 3. Enable the PHP Error Reporting In the terminal, execute: cd /etc/php5/apache2 ; sudo leafpad php.ini & Search and remove the comment instruction ; from display_errors Default Value: On Development Value: On Production Value: On error_reporting Default Value: E_ALL & ~E_NOTICE Development Value: E_ALL | E_STRICT Production Value: E_ALL & ~E_DEPRECATED
  • 4. Test a code with errors Restart apache from command line: sudo service apache2 restart Execute the following code: <?php print "error in the next line! What is it wrong?"; // after remove parint "aaa"; // after remove print phpinfo(); // dump all the info of the Apache and PHP ?> The error reporting can be very useful for debugging and for PHP beginners
  • 5. Install PHP My Admin Install Mysql Server, Mysql Client, PHP Mysql module and PHP My Admin: sudo apt-get install mysql-server-5.1 php5-mysql phpmyadmin Create an user and add specific permissions to the user, after create a database and add the the following tables: users books comments
  • 6. Users Table: Users Fields: id as integer, auto increment, primary ke login as string of 50 characters, index password as string of 50 characters role as string of 10 characters
  • 7. Books Table: Books Fields: id as integer, auto increment, primary ke title as string of 50 characters, index description as text pages as integer Add as many field you like to test the different type of data
  • 8. Comments Table: Comments Fields: id as integer, auto increment, primary ke user_id as integer, index book_id as integer, index comments as text Add as many field you like to test the different type of data
  • 9. Populate the database Populate the tables in the database with at least 5 records each. The following conditions should be followed: ● Table users with one user that has id = 10 ● Table books with one book that has id = 50 ● Table comments with one comment where the book_id = 50 and user_id = 10 We will play in the next slide using some advanced SQL queries (Join queries). http://dev.mysql.com/doc/ Use the right version!
  • 11. Open the PHP Manual Open the main reference for PHP: sudo apt-get install mysql-server-5.1 php5-mysql phpmyadmin Search for mysqli section or open: http://php.net/manual/en/book.mysqli.php Check in the manual the following commands: mysqli_connect $resource->query ($resource is the connection to the database) mysqli_fetch_array mysqli_prepare mysqli_stmt_bind_param mysqli_stmt_execute mysqli_stmt_get_result mysqli_close
  • 12. Search in the database (users) //connection: adapt the login/password/database name $link = mysqli_connect("localhost","root","password","test") or die("Error " . mysqli_error($link)); //consultation: $query = "SELECT * FROM users WHERE user_id <> 10" or die("Error in the consult." . mysqli_error($link)); //execute the query. $result = $link->query($query); //display information: while($row = mysqli_fetch_array($result)) { echo $row["name"] . "<br>"; } mysqli_close($link);
  • 13. Insert a value in the database $a = $_GET["a"]; if (isset($a)) { // is in one line! $link = mysqli_connect("localhost","root","password","test") or die("Error " . mysqli_error($link)); print $a; $query = "insert into users (name, password) values ('$a', 'abc')"; $result = $link->query($query); mysqli_close($link); } else { print "No variable "a" passed to the program <BR>"; print "user the following syntax filename.php?a=200"; }
  • 14. Execute a statement $query = "INSERT INTO books (login, password) VALUES (?,?)"; /* Prepare an insert statement */ $stmt = $mysqli->prepare($query); $stmt->bind_param("sss", $val1, $val2); $val1 = 'login-1'; $val2 = 'password-1'; $stmt->execute(); /* Execute the statement */ // another statement executed $val1 = 'login-2'; $val2 = 'password-2'; $stmt->execute(); /* close statement */ $stmt->close();
  • 15. Create a link in HTML We can link different pages as this example: <A HREF=”display.php?id=100”>Book title</A> In PHP can be used as: $id = 100; $title = “This is my book”; print “<A HREF=”display.php?id=$id”>$title</A>”;
  • 16. What's next? Propose us which subjects you want to explore, some examples can be : - Advanced PHP/HTML - PHP and Javascript - DEVOPS in practice - A real software developed in team using githu? e.g. Smart Farms
  • 17. Exercises  Link the page where you display the results to a new page were you display the values of a single record Display a page with all the comments of one specific book. The exercise can be performed using one or two SQL queries, in our case we want to use a single SQL join (decide which one you want to use).
  • 18. Exercises Delete a record in PHP using a parameter from HTML Update a table with some parameter received from the browser (HTML) and test the different type of data (e.g. integer, string, data, etc.) Install and use an example of the PDF module of PHP based on the previous slides (also use the slides of the previous workshops)