SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances (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
 

En vedette

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àGian17
 
Tutorial
TutorialTutorial
Tutorialbartooo
 
Fun early-readers-collection
Fun early-readers-collectionFun early-readers-collection
Fun early-readers-collectionYzus Suhaimi
 
Neurological Assessment
Neurological Assessment Neurological Assessment
Neurological Assessment Dorothy Claire
 

En vedette (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
 

Similaire à Php talk

PHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxPHP DATABASE MANAGEMENT.pptx
PHP DATABASE MANAGEMENT.pptxCynthiaKendi1
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.jssouridatta
 
Rits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdminRits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdminRight IT Services
 
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 doDave Stokes
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objectswebhostingguy
 
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 2016Codemotion
 
PHP: The easiest language to learn.
PHP: The easiest language to learn.PHP: The easiest language to learn.
PHP: The easiest language to learn.Binny V A
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessoradeel990
 
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 Projectxsist10
 
Introducation to php for beginners
Introducation to php for beginners Introducation to php for beginners
Introducation to php for beginners musrath mohammad
 
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.Adeoye Akintola
 

Similaire à 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.
 

Dernier

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Dernier (20)

The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

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