SlideShare a Scribd company logo
Working With PHP And DBs
Working With PHP And DBsIntroduction to PHP & DB
The Native Interface
The ODBC Interface
The ORM Model & Interface
Q & AIntroduction To PHP & DBFor many people, the main reason for learning PHP is because of the interaction with databases it can offer.
It is surprising how useful a database can be when used with a website.
There is a huge variety of things you can do when you interact the two, from displaying simple lists to running a complete website from a database. Why Would We Want A Database?Some examples of PHP and DBs being used together are:
Banner Rotation - Each banner is generated by PHP script. This opens the DB and picks a random banner from it to show the visitor. It also counts the number of times the banner has been viewed.
Forums- All the pages and messages in the forum are stored in the DB and are presented and updated by PHP  scripts.Why Would We Want A Database?Some examples of PHP and DBs being used together cont’d:
Databases – Storing user login and personal information, images, articles, item stock, sales data etc. All of these task can be done easily using PHP scripts.
Reports – The most popular product on site, the best article, the biggest image. Visitor counters and trails, from which countries our visitors come from? All of these question can be answered easily using PHP scripts.PHP & SQL ServersSame Machine			    Same Network (LAN)	                 Over The Internet (WAN)	Internet(WAN)
 Supported Database TypesSome of the DBs that PHP supports:How Does PHP Use A Database?There are three major strategies for using a DB:
The Native Interface – PHP connects directly to the SQL server using its native protocol, e.g. MySQL protocol version 10.
The ODBC Interface – The ODBC driver is used as a mediator between the PHP and the SQL server. PHP uses the ODBC API which translates the SQL dialect.
The ORM Interface – PHP uses objects which are mapped to DB tables and elements.Famous Sites That Use PHP & DB
Working With PHP And DBsIntroduction to PHP & DB
The Native Interface
The ODBC Interface
The ORM Model & Interface
Q & A
The Native InterfacePHP connects directly to the SQL server using its native protocol, e.g. MySQL protocol version 10.
Pros: Best performance. No drivers or mediators are used, hence the connection and queries are performed in optimal speed.
Cons: Compatibility. Each DB vendor has his own SQL dialect. Native MySQL code won’t run on ORACLE and vice versa.PHP MethodologySimple steps to follow:
Create a connection to the database.
Select database.
Compose an SQL statement (query, creation etc).
Submit the statement to the database.
Receive results from the database.
Parse results and use them.
Close database connection. Repeat these steps for multiplestatements
<?php$link = mysql_connect('localhost', 'root', '') 	or die('Could not connect: ' . mysql_error());mysql_select_db(dbname') 	or die('Could not select database');?>MySQL ConnectionPHP connects to the MySQL server:UsernameComputerPassword
<?phpmysql_query("SET character_set_client = utf8");mysql_query("SET character_set_connection = utf8");mysql_query("SET character_set_results = utf8"); ?>MySQL UTF-8Working with UTF-8 (Hebrew).<?php$sql= "SELECT * FROM students WHERE ID > 5 order by id";$result = mysql_query($sql) 	or die ("Unable to SELECT FROM DB: ".$sql);while($line = mysql_fetch_array($result, MYSQL_ASSOC)){	echo $line["id"]."<br/>";}?>MySQL QueryPreparing, sending and receiving the query.MYSQL_ASSOC – Associative Array      MYSQL_NUM – Numeric Array

More Related Content

What's hot (20)

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
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2
Gheyath M. Othman
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
Reaching Out From PL/SQL (OPP 2010)
Reaching Out From PL/SQL (OPP 2010)Reaching Out From PL/SQL (OPP 2010)
Reaching Out From PL/SQL (OPP 2010)
Lucas Jellema
 
15 expression-language
15 expression-language15 expression-language
15 expression-language
snopteck
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
Phpbasics
PhpbasicsPhpbasics
Phpbasics
PrinceGuru MS
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESS
jsmith92
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
mohamedsaad24
 
Php mysql
Php mysqlPhp mysql
Php mysql
Shehrevar Davierwala
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
Manish Bothra
 
Php Unit 1
Php Unit 1Php Unit 1
Php Unit 1
team11vgnt
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
Yuriy Krapivko
 
Web programming
Web programmingWeb programming
Web programming
Leo Mark Villar
 
Rails vs Web2py
Rails vs Web2pyRails vs Web2py
Rails vs Web2py
jonromero
 
php 1
php 1php 1
php 1
tumetr1
 
html
htmlhtml
html
tumetr1
 
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
 
Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2Web Development Course: PHP lecture 2
Web Development Course: PHP lecture 2
Gheyath M. Othman
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
Reaching Out From PL/SQL (OPP 2010)
Reaching Out From PL/SQL (OPP 2010)Reaching Out From PL/SQL (OPP 2010)
Reaching Out From PL/SQL (OPP 2010)
Lucas Jellema
 
15 expression-language
15 expression-language15 expression-language
15 expression-language
snopteck
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
Priti Solanki
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESS
jsmith92
 
Rails vs Web2py
Rails vs Web2pyRails vs Web2py
Rails vs Web2py
jonromero
 

Viewers also liked (19)

MySQLi
MySQLiMySQLi
MySQLi
Ankit Bahuguna
 
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Dave Stokes
 
PHP - Beginner's Workshop
PHP - Beginner's WorkshopPHP - Beginner's Workshop
PHP - Beginner's Workshop
Rafael Pinto
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
Jussi Pohjolainen
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
 
Shubhrat mishra working with php 2
Shubhrat mishra working with php 2Shubhrat mishra working with php 2
Shubhrat mishra working with php 2
Shubhrat Mishra
 
PHP & MySQL 教學
PHP & MySQL 教學PHP & MySQL 教學
PHP & MySQL 教學
Bo-Yi Wu
 
PHP CRUD Database Mysql
PHP CRUD Database MysqlPHP CRUD Database Mysql
PHP CRUD Database Mysql
Yusuf A.H.
 
CRUD html php mysql
CRUD html php mysqlCRUD html php mysql
CRUD html php mysql
Yesith Valencia
 
Database presentation
Database presentationDatabase presentation
Database presentation
webhostingguy
 
Technology labor ppt
Technology  labor pptTechnology  labor ppt
Technology labor ppt
Jaswinder Singh
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training Presentation
Nitesh Sharma
 
Basic quality concepts(3)
Basic quality concepts(3)Basic quality concepts(3)
Basic quality concepts(3)
ngiyari
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
webhostingguy
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
PHP Project PPT
PHP Project PPTPHP Project PPT
PHP Project PPT
Pankil Agrawal
 
Best Practices - PHP and the Oracle Database
Best Practices - PHP and the Oracle DatabaseBest Practices - PHP and the Oracle Database
Best Practices - PHP and the Oracle Database
Christopher Jones
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
Karmatechnologies Pvt. Ltd.
 
Impact of technology on education
Impact of technology on educationImpact of technology on education
Impact of technology on education
Max Inder
 
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015Database Basics with PHP -- Connect JS Conference October 17th, 2015
Database Basics with PHP -- Connect JS Conference October 17th, 2015
Dave Stokes
 
PHP - Beginner's Workshop
PHP - Beginner's WorkshopPHP - Beginner's Workshop
PHP - Beginner's Workshop
Rafael Pinto
 
Short Intro to PHP and MySQL
Short Intro to PHP and MySQLShort Intro to PHP and MySQL
Short Intro to PHP and MySQL
Jussi Pohjolainen
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
 
Shubhrat mishra working with php 2
Shubhrat mishra working with php 2Shubhrat mishra working with php 2
Shubhrat mishra working with php 2
Shubhrat Mishra
 
PHP & MySQL 教學
PHP & MySQL 教學PHP & MySQL 教學
PHP & MySQL 教學
Bo-Yi Wu
 
PHP CRUD Database Mysql
PHP CRUD Database MysqlPHP CRUD Database Mysql
PHP CRUD Database Mysql
Yusuf A.H.
 
Database presentation
Database presentationDatabase presentation
Database presentation
webhostingguy
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training Presentation
Nitesh Sharma
 
Basic quality concepts(3)
Basic quality concepts(3)Basic quality concepts(3)
Basic quality concepts(3)
ngiyari
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
kalaisai
 
Best Practices - PHP and the Oracle Database
Best Practices - PHP and the Oracle DatabaseBest Practices - PHP and the Oracle Database
Best Practices - PHP and the Oracle Database
Christopher Jones
 
Impact of technology on education
Impact of technology on educationImpact of technology on education
Impact of technology on education
Max Inder
 
Ad

Similar to working with PHP & DB's (20)

P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
phelios
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
Wildan Maulana
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung
 
Php Data Objects
Php Data ObjectsPhp Data Objects
Php Data Objects
hiren.joshi
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questions
sekar c
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
Anil Kumar Panigrahi
 
wamp.ppt
wamp.pptwamp.ppt
wamp.ppt
Imran Kedim
 
PHP on Windows and on Azure
PHP on Windows and on AzurePHP on Windows and on Azure
PHP on Windows and on Azure
Maarten Balliauw
 
Sa
SaSa
Sa
sahul azzez m.i
 
Top 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersTop 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and Answers
Vineet Kumar Saini
 
Phphacku iitd
Phphacku iitdPhphacku iitd
Phphacku iitd
Sorabh Jain
 
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
Dave Stokes
 
Php Interview Questions
Php Interview QuestionsPhp Interview Questions
Php Interview Questions
UmeshSingh159
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
JAX London
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworks
guestf7bc30
 
php
phpphp
php
ajeetjhajharia
 
My Saminar On Php
My Saminar On PhpMy Saminar On Php
My Saminar On Php
Arjun Kumawat
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
Google Developer Students Club NIT Silchar
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
phelios
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
Wildan Maulana
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung
 
Web Application Introduction
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung
 
Php Data Objects
Php Data ObjectsPhp Data Objects
Php Data Objects
hiren.joshi
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questions
sekar c
 
PHP on Windows and on Azure
PHP on Windows and on AzurePHP on Windows and on Azure
PHP on Windows and on Azure
Maarten Balliauw
 
Top 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and AnswersTop 100 PHP Interview Questions and Answers
Top 100 PHP Interview Questions and Answers
Vineet Kumar Saini
 
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
Dave Stokes
 
Php Interview Questions
Php Interview QuestionsPhp Interview Questions
Php Interview Questions
UmeshSingh159
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardArchitecture | Busy Java Developers Guide to NoSQL | Ted Neward
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
JAX London
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworks
guestf7bc30
 
Ad

Recently uploaded (20)

Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 

working with PHP & DB's

  • 2. Working With PHP And DBsIntroduction to PHP & DB
  • 5. The ORM Model & Interface
  • 6. Q & AIntroduction To PHP & DBFor many people, the main reason for learning PHP is because of the interaction with databases it can offer.
  • 7. It is surprising how useful a database can be when used with a website.
  • 8. There is a huge variety of things you can do when you interact the two, from displaying simple lists to running a complete website from a database. Why Would We Want A Database?Some examples of PHP and DBs being used together are:
  • 9. Banner Rotation - Each banner is generated by PHP script. This opens the DB and picks a random banner from it to show the visitor. It also counts the number of times the banner has been viewed.
  • 10. Forums- All the pages and messages in the forum are stored in the DB and are presented and updated by PHP scripts.Why Would We Want A Database?Some examples of PHP and DBs being used together cont’d:
  • 11. Databases – Storing user login and personal information, images, articles, item stock, sales data etc. All of these task can be done easily using PHP scripts.
  • 12. Reports – The most popular product on site, the best article, the biggest image. Visitor counters and trails, from which countries our visitors come from? All of these question can be answered easily using PHP scripts.PHP & SQL ServersSame Machine Same Network (LAN) Over The Internet (WAN) Internet(WAN)
  • 13. Supported Database TypesSome of the DBs that PHP supports:How Does PHP Use A Database?There are three major strategies for using a DB:
  • 14. The Native Interface – PHP connects directly to the SQL server using its native protocol, e.g. MySQL protocol version 10.
  • 15. The ODBC Interface – The ODBC driver is used as a mediator between the PHP and the SQL server. PHP uses the ODBC API which translates the SQL dialect.
  • 16. The ORM Interface – PHP uses objects which are mapped to DB tables and elements.Famous Sites That Use PHP & DB
  • 17. Working With PHP And DBsIntroduction to PHP & DB
  • 20. The ORM Model & Interface
  • 21. Q & A
  • 22. The Native InterfacePHP connects directly to the SQL server using its native protocol, e.g. MySQL protocol version 10.
  • 23. Pros: Best performance. No drivers or mediators are used, hence the connection and queries are performed in optimal speed.
  • 24. Cons: Compatibility. Each DB vendor has his own SQL dialect. Native MySQL code won’t run on ORACLE and vice versa.PHP MethodologySimple steps to follow:
  • 25. Create a connection to the database.
  • 27. Compose an SQL statement (query, creation etc).
  • 28. Submit the statement to the database.
  • 29. Receive results from the database.
  • 30. Parse results and use them.
  • 31. Close database connection. Repeat these steps for multiplestatements
  • 32. <?php$link = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());mysql_select_db(dbname') or die('Could not select database');?>MySQL ConnectionPHP connects to the MySQL server:UsernameComputerPassword
  • 33. <?phpmysql_query("SET character_set_client = utf8");mysql_query("SET character_set_connection = utf8");mysql_query("SET character_set_results = utf8"); ?>MySQL UTF-8Working with UTF-8 (Hebrew).<?php$sql= "SELECT * FROM students WHERE ID > 5 order by id";$result = mysql_query($sql) or die ("Unable to SELECT FROM DB: ".$sql);while($line = mysql_fetch_array($result, MYSQL_ASSOC)){ echo $line["id"]."<br/>";}?>MySQL QueryPreparing, sending and receiving the query.MYSQL_ASSOC – Associative Array MYSQL_NUM – Numeric Array
  • 34. <?phpmysql_close($link);?>MySQL CloseClosing the connection (Very important).Working With PHP And DBsIntroduction to PHP & DB
  • 37. The ORM Model & Interface
  • 38. Q & AODBC Connectivity Diagram
  • 39. PHP & ODBCODBC - Open Database Connectivity provides a standard software API method for using database management systems (DBMS).
  • 40. In Windows, programming interfaces allow any application to talk to any printer or database by way of a “centralized manager”.
  • 41. The API that applications use on Windows to access the database "manager" is titled ODBC.ODBC InstallationODBC can be obtained for free at: http://dev.mysql.com/downloads/connector/odbc/5.1.html
  • 42. After a quick standard (next…next…) installation, make the following adjustments:
  • 43. Open the Administrative Tools icon in your Control Panel.
  • 44. Double-click on the Data Sources (ODBC) icon inside.
  • 45. Choose the System DSN tab and click on Add.
  • 46. Select the Microsoft Access Driver. Click Finish.
  • 47. In the next screen, click Select to locate the database.
  • 48. Give the database a Data Source Name (DSN).<?php$conn = odbc_connect('MySQL','user','password');....odbc_close($conn);?>PHP SQL ConnectThe odbc_connect() function is used for connecting to the database we configured in the ODBC driver.
  • 49. This function receives a database name (DSN), a user name and a password. It returns a database handle.Closing the connection
  • 50. <?php$conn=odbc_connect('MySQL','root','');if (!$conn) { exit("Connection Failed: " . $conn);}$sql="SELECT * FROM customer";?>PHP SQL QueryAfter the connection we create a String variable that holds the SQL Query:Error Handling
  • 51. <?php$rs= odbc_exec($conn,$sql);if (!$rs) {exit("Error in SQL");}while (odbc_fetch_row($rs)){echo odbc_result($rs,1);echo odbc_result($rs,2)."<br/>";}?>PHP SQL ResultsFirst we execute the query using odbc_exec().
  • 52. Second we use odbc_fetch_row() and odbc_result() to print the result to the user.Error Handling
  • 53. <?php$conn = odbc_connect('MySQL','root','');if (!$conn) {exit("Connection Failed: " . $conn);}$sql="SELECT * FROM customer";$rs= odbc_exec($conn,$sql);if (!$rs) {exit("Error in SQL");}while (odbc_fetch_row($rs)){echo odbc_result($rs,1);echo odbc_result($rs,2)."<br/>";}odbc_close($conn);?>Bringing it all together
  • 54. Working With PHP And DBsIntroduction to PHP & DB
  • 57. The ORM Model & Interface
  • 58. Q & AIntroduction To ORMObject Relational Mapping, is a database design approach that simplifies managing complex databases for programmers.
  • 59. The ORM layer in a PHP can make “objects” stored in a database behave like actual objects from a programming perspective.
  • 60. This way creating a new user would become very simple such as $user->new().MVC RecapThe user interacts with the user interface in some way. The controller handles the input event from the user interface, and converts the event into an appropriate user action, understandable for the model.The controller notifies the model of the user action, possibly resulting in a change in the model's state. A view queries the model in order to generate an appropriate user interface. The view gets its own data from the modelThe user interface waits for further user interactions, which restarts the control flow cycle.
  • 61. ORM ImplementationsBy abstracting actual database access, web development can be more productive and result in more reliable applications.
  • 62. ORM is very common among PHP frameworks, such as:<?phpclass Student extends DataMapper{public $has_many= array('course');public function __construct() { parent::__construct(); }}class Course extends DataMapper{public $has_many= array('student');public function __construct() { parent::__construct(); }}?>ORM Student ExampleModel classes for the student DB application.The classes represent entities which were defined in the DB.The classes could be given any relevant functionality.
  • 63. class Students extends Controller {public function __construct() {parent::__construct();$this->load->model('Student');$this->load->helper('url');$this->load->library('pagination'); }function index($offset=0) { $student_list= new Student();$total_rows= $student_list->count();$student_list->order_by('name'); $data['student_list'] = $student_list->get(5, $offset)->all; $config['base_url'] = site_url("students");$config['total_rows'] = $total_rows;$config['per_page'] = '5';$this->pagination->initialize($config); $this->load->view('student/index', $data); } }ORM Student ExampleController class for the students DB application.The class represents the functionality if the DB in queries.The classes could be given any relevant functionality.
  • 64. <table><tr><th>Name</th><th>Course</th></tr><?php$ctr= 0; ?><?phpforeach($student_listas $student): ?><?php$student->course->get()->order_by('name'); ?><?php$ctr++ ?><?phpif ($ctr% 2): ?><tr><td><?= $student->name ?></td><td><?foreach($student->course->all as $course): ?><?= $course->name ?><br/><?endforeach?></td></tr><?phpelse: ?><trclass="odd"><td> <?= $student->name ?></td><td> <?foreach($student->course->all as $course): ?><?= $course->name ?><br/><?endforeach?></td></tr><?phpendif; ?><?phpendforeach?></table>ORM Student ExampleViewer class for the students DB application.The class represents the UI that is presented to the user.The classes could be given any relevant design.
  • 65. Q & A