SlideShare ist ein Scribd-Unternehmen logo
1 von 15
PHP
What is PHP 
 What is PHP? 
 PHP is an acronym for "PHP Hypertext Preprocessor" 
 PHP is a widely-used, open source scripting language 
 PHP scripts are executed on the server 
 PHP costs nothing, it is free to download and use 
 Note PHP is an amazing and popular language! 
 It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)! 
 It is deep enough to run the largest social network (Facebook)! 
 It is also easy enough to be a beginner's first server side language! 
 text, such as XHTML and XML.
What is a PHP File? 
 PHP files can contain text, HTML, CSS, JavaScript, and PHP code 
 PHP code are executed on the server, and the result is returned to the browser as plain HTML 
 PHP files have extension ".php" 
 What Can PHP Do? 
 PHP can generate dynamic page content 
 PHP can create, open, read, write, delete, and close files on the server 
 PHP can collect form data 
 PHP can send and receive cookies 
 PHP can add, delete, modify data in your database 
 PHP can restrict users to access some pages on your website 
 PHP can encrypt data 
 With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any
Why PHP? 
 PHP runs on various platforms (Windows, Linux, Unix, 
Mac OS X, etc.) 
 PHP is compatible with almost all servers used today 
(Apache, IIS, etc.) 
 PHP supports a wide range of databases 
 PHP is free. Download it from the official PHP resource: 
www.php.net 
 PHP is easy to learn and runs efficiently on the server 
side
Connecting to Database 
 Database Driver 
 PDO (PHP Data Objects) is a database driver the will work on 12 different database systems. It comes 
pre-installed with php5 
<?php 
$servername = "localhost"; 
$username = "username"; 
$password = "password"; 
try { 
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password); 
echo "Connected successfully"; 
} 
catch(PDOException $e) 
{ 
echo $e->getMessage(); 
} 
?>
Creating a Database 
<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "root”; 
try { 
$conn = new PDO("mysql:host=$servername;dbname=COSC531", $username, $password); 
// set the PDO error mode to exception 
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$sql = "CREATE DATABASE myDBPDO"; 
// use exec() because no results are returned 
$conn->exec($sql); 
echo "Database created successfully"; 
} 
catch(PDOException $e) 
{ 
echo $sql . "<br>" . $e->getMessage();
Creating a Table 
<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "myDBPDO"; 
try { 
$conn = new PDO("mysql:host=$servername;dbname=myDBPDO", $username, $password); 
// set the PDO error mode to exception 
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
// sql to create table 
$sql = "CREATE TABLE MyGuests ( 
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
firstname VARCHAR(30) NOT NULL, 
lastname VARCHAR(30) NOT NULL,
Inserting into a Table 
<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "myDBPDO"; 
try { 
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); 
// set the PDO error mode to exception 
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$sql = "INSERT INTO MyGuests (firstname, lastname, email) 
VALUES ('John', 'Doe', 'john@example.com')"; 
// use exec() because no results are returned 
$conn->exec($sql); 
echo "New record created successfully"; 
}
Last Id inserted 
<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "myDBPDO"; 
try { 
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); 
// set the PDO error mode to exception 
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$sql = "INSERT INTO MyGuests (firstname, lastname, email) 
VALUES ('John', 'Doe', 'john@example.com')"; 
// use exec() because no results are returned 
$conn->exec($sql); 
$last_id = $conn->lastInsertId(); 
echo "New record created successfully. Last inserted ID is: " . $last_id;
Inserting Multiple Records 
<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "myDBPDO"; 
try { 
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); 
// set the PDO error mode to exception 
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
// begin the transaction 
$conn->beginTransaction(); 
// our SQL statememtns 
$conn->exec("INSERT INTO MyGuests (firstname, lastname, email) 
VALUES ('John', 'Doe', 'john@example.com')");
Select 
<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "myDBPDO"; 
// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
die("Connection failed: " . $conn->connect_error); 
} 
$sql = "SELECT id, firstname, lastname FROM MyGuests"; 
$result = $conn->query($sql);
Delete from Table 
<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "myDBPDO"; 
try { 
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); 
// set the PDO error mode to exception 
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
// sql to delete a record 
$sql = "DELETE FROM MyGuests WHERE id=3"; 
// use exec() because no results are returned 
$conn->exec($sql);
Delete from Table 
<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "myDBPDO"; 
try { 
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); 
// set the PDO error mode to exception 
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$sql = "UPDATE MyGuests SET lastname='Doey' WHERE id=2"; 
// Prepare statement 
$stmt = $conn->prepare($sql);
Do I actually use this? 
 NO! 
 I use framworks that encapsilate the DB operation 
 Drupal uses operations on nodes and entity to develop 
queries in the background 
 Symphony/Laravel user ORM(object relational 
mapping) to develop queries in the backgroud
If the framework does the work, 
Why do I need to know this 
 Without an understanding of the underlying architecture 
and techniques to manipulate that architechture

Weitere ähnliche Inhalte

Was ist angesagt?

PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1
Kanchilug
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 

Was ist angesagt? (19)

TICT #13
TICT #13TICT #13
TICT #13
 
Not Really PHP by the book
Not Really PHP by the bookNot Really PHP by the book
Not Really PHP by the book
 
Intro to php
Intro to phpIntro to php
Intro to php
 
Session handling in php
Session handling in phpSession handling in php
Session handling in php
 
Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
 
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
 
Php hacku
Php hackuPhp hacku
Php hacku
 
Coding for php with mysql
Coding for php with mysqlCoding for php with mysql
Coding for php with mysql
 
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
 
My shell
My shellMy shell
My shell
 
Cpsh sh
Cpsh shCpsh sh
Cpsh sh
 
PHP an intro -1
PHP an intro -1PHP an intro -1
PHP an intro -1
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Phphacku iitd
Phphacku iitdPhphacku iitd
Phphacku iitd
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
PHP for hacks
PHP for hacksPHP for hacks
PHP for hacks
 
PHP and Databases
PHP and DatabasesPHP and Databases
PHP and Databases
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
File system
File systemFile system
File system
 

Andere mochten auch

Andere mochten auch (6)

Modernisme1.12
Modernisme1.12Modernisme1.12
Modernisme1.12
 
H3 expressionisme
H3 expressionismeH3 expressionisme
H3 expressionisme
 
Vita di paese e vita di città
Vita di paese e vita di cittàVita di paese e vita di città
Vita di paese e vita di città
 
Tutorial
TutorialTutorial
Tutorial
 
Fun early-readers-collection
Fun early-readers-collectionFun early-readers-collection
Fun early-readers-collection
 
Neurological Assessment
Neurological Assessment Neurological Assessment
Neurological Assessment
 

Ähnlich wie Php talk

PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptx
CynthiaKendi1
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
souridatta
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objects
webhostingguy
 

Ähnlich wie Php talk (20)

Php with mysql ppt
Php with mysql pptPhp with mysql ppt
Php with mysql ppt
 
PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptx
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
Rits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdminRits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdmin
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
 
Fatc
FatcFatc
Fatc
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objects
 
Web 10 | PHP with MySQL
Web 10 | PHP with MySQLWeb 10 | PHP with MySQL
Web 10 | PHP with MySQL
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
PHP: The easiest language to learn.
PHP: The easiest language to learn.PHP: The easiest language to learn.
PHP: The easiest language to learn.
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Php Training Workshop by Vtips
Php Training Workshop by VtipsPhp Training Workshop by Vtips
Php Training Workshop by Vtips
 
Php with my sql
Php with my sqlPhp with my sql
Php with my sql
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessor
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
php part 2
php part 2php part 2
php part 2
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners
 
Php basics
Php basicsPhp basics
Php basics
 
Create a res tful services api in php.
Create a res tful services api in php.Create a res tful services api in php.
Create a res tful services api in php.
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Php talk

  • 1. PHP
  • 2. What is PHP  What is PHP?  PHP is an acronym for "PHP Hypertext Preprocessor"  PHP is a widely-used, open source scripting language  PHP scripts are executed on the server  PHP costs nothing, it is free to download and use  Note PHP is an amazing and popular language!  It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)!  It is deep enough to run the largest social network (Facebook)!  It is also easy enough to be a beginner's first server side language!  text, such as XHTML and XML.
  • 3. What is a PHP File?  PHP files can contain text, HTML, CSS, JavaScript, and PHP code  PHP code are executed on the server, and the result is returned to the browser as plain HTML  PHP files have extension ".php"  What Can PHP Do?  PHP can generate dynamic page content  PHP can create, open, read, write, delete, and close files on the server  PHP can collect form data  PHP can send and receive cookies  PHP can add, delete, modify data in your database  PHP can restrict users to access some pages on your website  PHP can encrypt data  With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any
  • 4. Why PHP?  PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)  PHP is compatible with almost all servers used today (Apache, IIS, etc.)  PHP supports a wide range of databases  PHP is free. Download it from the official PHP resource: www.php.net  PHP is easy to learn and runs efficiently on the server side
  • 5. Connecting to Database  Database Driver  PDO (PHP Data Objects) is a database driver the will work on 12 different database systems. It comes pre-installed with php5 <?php $servername = "localhost"; $username = "username"; $password = "password"; try { $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password); echo "Connected successfully"; } catch(PDOException $e) { echo $e->getMessage(); } ?>
  • 6. Creating a Database <?php $servername = "localhost"; $username = "root"; $password = "root”; try { $conn = new PDO("mysql:host=$servername;dbname=COSC531", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "CREATE DATABASE myDBPDO"; // use exec() because no results are returned $conn->exec($sql); echo "Database created successfully"; } catch(PDOException $e) { echo $sql . "<br>" . $e->getMessage();
  • 7. Creating a Table <?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "myDBPDO"; try { $conn = new PDO("mysql:host=$servername;dbname=myDBPDO", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // sql to create table $sql = "CREATE TABLE MyGuests ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL,
  • 8. Inserting into a Table <?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "myDBPDO"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')"; // use exec() because no results are returned $conn->exec($sql); echo "New record created successfully"; }
  • 9. Last Id inserted <?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "myDBPDO"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')"; // use exec() because no results are returned $conn->exec($sql); $last_id = $conn->lastInsertId(); echo "New record created successfully. Last inserted ID is: " . $last_id;
  • 10. Inserting Multiple Records <?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "myDBPDO"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // begin the transaction $conn->beginTransaction(); // our SQL statememtns $conn->exec("INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')");
  • 11. Select <?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "myDBPDO"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT id, firstname, lastname FROM MyGuests"; $result = $conn->query($sql);
  • 12. Delete from Table <?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "myDBPDO"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // sql to delete a record $sql = "DELETE FROM MyGuests WHERE id=3"; // use exec() because no results are returned $conn->exec($sql);
  • 13. Delete from Table <?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "myDBPDO"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "UPDATE MyGuests SET lastname='Doey' WHERE id=2"; // Prepare statement $stmt = $conn->prepare($sql);
  • 14. Do I actually use this?  NO!  I use framworks that encapsilate the DB operation  Drupal uses operations on nodes and entity to develop queries in the background  Symphony/Laravel user ORM(object relational mapping) to develop queries in the backgroud
  • 15. If the framework does the work, Why do I need to know this  Without an understanding of the underlying architecture and techniques to manipulate that architechture