SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
>_ 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)

Más contenido relacionado

La actualidad más candente

GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 
Simple php backdoor_by_dk
Simple php backdoor_by_dkSimple php backdoor_by_dk
Simple php backdoor_by_dk
Stan Adrian
 
Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1
beckman16
 

La actualidad más candente (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
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
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
 
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
 
Php session 3 Important topics
Php session 3 Important topicsPhp session 3 Important topics
Php session 3 Important topics
 
Add loop shortcode
Add loop shortcodeAdd loop shortcode
Add loop shortcode
 
M.php
M.phpM.php
M.php
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
 
Client-side Storage 
Client-side Storage Client-side Storage 
Client-side Storage 
 
Sah
SahSah
Sah
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Php - Getting good with session
Php - Getting good with sessionPhp - Getting good with session
Php - Getting good with session
 
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
 
Simple php backdoor_by_dk
Simple php backdoor_by_dkSimple php backdoor_by_dk
Simple php backdoor_by_dk
 
Php
PhpPhp
Php
 
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
 
Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1Drupalxamppxp 1229687989691791 1
Drupalxamppxp 1229687989691791 1
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
 
Installing odoo v8 from github
Installing odoo v8 from githubInstalling odoo v8 from github
Installing odoo v8 from github
 

Destacado

Senior Life PDF
Senior Life PDFSenior Life PDF
Senior Life PDF
Sam Ayerst
 

Destacado (18)

pse eshte e domosdoshme kursimi i energjise elektrike
pse eshte e domosdoshme kursimi i energjise elektrikepse eshte e domosdoshme kursimi i energjise elektrike
pse eshte e domosdoshme kursimi i energjise elektrike
 
Temperature Sensor Thermocouple and RTD
Temperature Sensor Thermocouple and RTDTemperature Sensor Thermocouple and RTD
Temperature Sensor Thermocouple and RTD
 
(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 - introduction to programming
Things lab - introduction to programmingThings lab - introduction to programming
Things lab - introduction to programming
 
The Matrimonial Strategist,
The Matrimonial Strategist,The Matrimonial Strategist,
The Matrimonial Strategist,
 
Introduction to HireIQ Solutions
Introduction to HireIQ SolutionsIntroduction to HireIQ Solutions
Introduction to HireIQ Solutions
 
RateMyClothes application
RateMyClothes applicationRateMyClothes application
RateMyClothes application
 
Banking Services
Banking ServicesBanking Services
Banking Services
 
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
 
Samsung galaxy s6
Samsung galaxy s6Samsung galaxy s6
Samsung galaxy s6
 
Divorce Budget Worksheet
Divorce Budget WorksheetDivorce Budget Worksheet
Divorce Budget Worksheet
 
Workforce Analysis and Education Alignment Strategy
Workforce Analysis and Education Alignment StrategyWorkforce Analysis and Education Alignment Strategy
Workforce Analysis and Education Alignment Strategy
 
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
 
ปลุกจิตคณิต ม.4 - ฟังก์ชั่น
ปลุกจิตคณิต ม.4 - ฟังก์ชั่นปลุกจิตคณิต ม.4 - ฟังก์ชั่น
ปลุกจิตคณิต ม.4 - ฟังก์ชั่น
 
Senior Life PDF
Senior Life PDFSenior Life PDF
Senior Life PDF
 
Question 7
Question 7Question 7
Question 7
 
Dhruvit.ppt
Dhruvit.pptDhruvit.ppt
Dhruvit.ppt
 
Question 6
Question 6Question 6
Question 6
 

Similar a PHP and Databases

Tips
TipsTips
Tips
mclee
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
How to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdfHow to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdf
Appweb Coders
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
souridatta
 
1 Introduction to PHP Overview This lab walks y.docx
1  Introduction to PHP Overview This lab walks y.docx1  Introduction to PHP Overview This lab walks y.docx
1 Introduction to PHP Overview This lab walks y.docx
honey725342
 
3. build your own php extension ai ti aptech
3. build your own php extension   ai ti aptech3. build your own php extension   ai ti aptech
3. build your own php extension ai ti aptech
Quang Anh Le
 
07 build your-own_php_extension
07 build your-own_php_extension07 build your-own_php_extension
07 build your-own_php_extension
Nguyen Duc Phu
 

Similar a PHP and Databases (20)

CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Power shell training
Power shell trainingPower shell training
Power shell training
 
18.register login
18.register login18.register login
18.register login
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
PHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web DevelopmentPHP and MySQL : Server Side Scripting For Web Development
PHP and MySQL : Server Side Scripting For Web Development
 
PHP and MySQL.ppt
PHP and MySQL.pptPHP and MySQL.ppt
PHP and MySQL.ppt
 
Tips
TipsTips
Tips
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
Php session
Php sessionPhp session
Php session
 
How to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdfHow to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdf
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
1 Introduction to PHP Overview This lab walks y.docx
1  Introduction to PHP Overview This lab walks y.docx1  Introduction to PHP Overview This lab walks y.docx
1 Introduction to PHP Overview This lab walks y.docx
 
Intro to php
Intro to phpIntro to php
Intro to php
 
3. build your own php extension ai ti aptech
3. build your own php extension   ai ti aptech3. build your own php extension   ai ti aptech
3. build your own php extension ai ti aptech
 
07 build your-own_php_extension
07 build your-own_php_extension07 build your-own_php_extension
07 build your-own_php_extension
 

Más de Things Lab

Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with Git
Things Lab
 

Más de 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 - Intro fritzing
Things lab - Intro fritzingThings lab - Intro fritzing
Things lab - Intro fritzing
 
Real world Webapp
Real world WebappReal world Webapp
Real world Webapp
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
 
Website with HTML CSS
Website with HTML CSSWebsite with HTML CSS
Website with HTML CSS
 
Arduino
ArduinoArduino
Arduino
 
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
 
Source Code Management with Git
Source Code Management with GitSource Code Management with Git
Source Code Management with Git
 
Some hours of python
Some hours of pythonSome hours of python
Some hours of python
 
An Hour of Arduino and Ardublock
An Hour of Arduino and ArdublockAn Hour of Arduino and Ardublock
An Hour of Arduino and Ardublock
 

Último

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Último (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 

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)