SlideShare a Scribd company logo
1 of 18
Database Basics




The power behind your web application
Overview
Objective

Learn the basics of connecting to a database and
executing sql queries ProdigyView.

Requirements

 A Mysql, Postrgesql or MSSQL database
Estimated Time

10 Minutes
Follow Along With Code
           Example
1. Download a copy of the example code at
  www.prodigyview.com/source.

2. Install the system in an environment you feel
  comfortable testing in.

3. Proceed to examples/database/Database.php
A Brief Note About The
               Database
Even though you can write a complete application in
ProdigyView without using the database, it is more than likely
that you are going to need the database at some point. The
great feature that PVDatabase has is that it can connect to
MySQL, PostgreSQL and MSSQL. In this tutorial we are
going to learn:
 Connecting to a database
 Executing A Query
 Iterating Through Results
Current development is being done for MongoDB and
SQLITE
Disabling the Database
If we are going to learn about truly manipulating the
database, let’s first boot ProdigyView in a way that
disables the database. Turn the database initialization off
and loading the plug-ins off since they require a database
connection.




Boot System                   Disable Options
Set a database
Good, now with the database not initialized, we are going
to configure a connection. Similar to the database
configuration file, we are putting our database variables in
an array.
Time to Connect
In our last slide, we created configuration paramters for a
database we have access too. Next we are going to add
the connection to PVDatabase and then connect to it.


 Name of the connection                Connection Parameters




  Connect to a specified database. Use to switch between connections
Create a table
We are going to need a table to test with, so now lets
create one. The process of creating tables is in another
tutorial but we will give you a glimpse of it.
Sanitizing Data
 When a user is inputting data, it is a general rule NOT to
 trust that data because it might contain malicious code
 that can wreak havoc on your database. Before inputting
 any information into your database through a
 query, sanitize it through makeSafe() function.

Data after it is sanitized      Data to be sanitized




                                Data to be sanitized
Executing
1. We have our connection set
2. We have a table and columns
3. We sanitized our information
4. We are ready for executing our first query.

                       Insert query with our sanitized data




  Executes any query
Again but get the id
     Great, we now know how to insert data into the database.
     But what if we want the id of the last entry? No problem.
     Let’s run our example again except this time we are going
     to execute using the return_last_insert_query();

 The generated id




The column that contains the auto incrementing id
                                                The table to return the column from
A Closer Look


The method return_last_insert_query(); takes the query
and to additional arguments. The arguments are the
column to be returned and the table to return the column
from.
These options are here because some databases require
that there is a specified column or table to return the last
generated id. If you want to make your application
database agnostic, it is suggested that these
parameters be used.
Find Results – Row Count
PVDatabase::query executes any query so it can be
used for creating, updating, finding and deleting. But how
to we get the results that are found?

Not a problem. Let’s create a search querying and get row
count.




            Count the rows in the result
Find Results – Row Iteration
That query in the previous slide will find the rows that we
had previously inputted. Use the same $result with the
method PVDatabase::fetchArray() to return an array of
found data to iterate through.
Challenge!
Ok so we have the database basics down. So here is your
challenge, it two parts

1. Add connections to multiple database and switch
   between those connections

2. Execute a select query on a database but use
   fetchFields() instead of fetchArray.
The Not So Obvious
1. The function setConnection will close the connection
   to the current database and open a connection to a
   new one.

2. All the database methods are designed to
   automatically work with the set database

3. Other methods in ProdigyView, such as when creating
   content, will automatically sanitize data for you.

4. PVDatabase::makeSafe can also sanitize arrays
Summary
1. Add a connection by using
   PVDatabase::addConnection()

2. Connection to a database using
   PVDatabase::setConnection()

3. Sanitize data before inserting into the database by
   using PVDatabase::makeSafe()

4. Execute a query using PVDatabase::query();
5. Fetch results by using PVDatabase::fetchArray();
API Reference
For a better understanding of the database, visit the api
by clicking on the link below.

PVDatabase




                 More Tutorials
For more tutorials, please visit:

http://www.prodigyview.com/tutorials


                       www.prodigyview.com

More Related Content

What's hot

Database Concepts and Terminologies
Database Concepts and TerminologiesDatabase Concepts and Terminologies
Database Concepts and TerminologiesOusman Faal
 
Introduction to database & sql
Introduction to database & sqlIntroduction to database & sql
Introduction to database & sqlzahid6
 
Week 1 Before the Advent of Database Systems & Fundamental Concepts
Week 1 Before the Advent of Database Systems & Fundamental ConceptsWeek 1 Before the Advent of Database Systems & Fundamental Concepts
Week 1 Before the Advent of Database Systems & Fundamental Conceptsoudesign
 
Week 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data ModelWeek 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data Modeloudesign
 
Se 381 - lec 21 - 23 - 12 may09 - df-ds and data dictionary
Se 381 - lec 21 - 23 - 12 may09 - df-ds and data dictionarySe 381 - lec 21 - 23 - 12 may09 - df-ds and data dictionary
Se 381 - lec 21 - 23 - 12 may09 - df-ds and data dictionarybabak danyal
 
Database Design
Database DesignDatabase Design
Database Designlearnt
 
Week 1 Lab Directions
Week 1 Lab DirectionsWeek 1 Lab Directions
Week 1 Lab Directionsoudesign
 
Abap data dictionary
Abap data dictionaryAbap data dictionary
Abap data dictionarySmartGokul4
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database DesignArchit Saxena
 
Introduction to databases
Introduction to databasesIntroduction to databases
Introduction to databasesBryan Corpuz
 
Introduction to database with ms access.hetvii
Introduction to database with ms access.hetviiIntroduction to database with ms access.hetvii
Introduction to database with ms access.hetvii07HetviBhagat
 
Training MS Access 2007
Training MS Access 2007Training MS Access 2007
Training MS Access 2007crespoje
 
Database Concepts and Components
Database Concepts and ComponentsDatabase Concepts and Components
Database Concepts and ComponentsRIAH ENCARNACION
 

What's hot (19)

Database Concepts and Terminologies
Database Concepts and TerminologiesDatabase Concepts and Terminologies
Database Concepts and Terminologies
 
Introduction to database & sql
Introduction to database & sqlIntroduction to database & sql
Introduction to database & sql
 
Week 1 Before the Advent of Database Systems & Fundamental Concepts
Week 1 Before the Advent of Database Systems & Fundamental ConceptsWeek 1 Before the Advent of Database Systems & Fundamental Concepts
Week 1 Before the Advent of Database Systems & Fundamental Concepts
 
Week 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data ModelWeek 4 The Relational Data Model & The Entity Relationship Data Model
Week 4 The Relational Data Model & The Entity Relationship Data Model
 
Se 381 - lec 21 - 23 - 12 may09 - df-ds and data dictionary
Se 381 - lec 21 - 23 - 12 may09 - df-ds and data dictionarySe 381 - lec 21 - 23 - 12 may09 - df-ds and data dictionary
Se 381 - lec 21 - 23 - 12 may09 - df-ds and data dictionary
 
Database Design
Database DesignDatabase Design
Database Design
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
Database fundamentals
Database fundamentalsDatabase fundamentals
Database fundamentals
 
Week 1 Lab Directions
Week 1 Lab DirectionsWeek 1 Lab Directions
Week 1 Lab Directions
 
Abap data dictionary
Abap data dictionaryAbap data dictionary
Abap data dictionary
 
RDBMS concepts
RDBMS conceptsRDBMS concepts
RDBMS concepts
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
Introduction to databases
Introduction to databasesIntroduction to databases
Introduction to databases
 
Introduction to database with ms access.hetvii
Introduction to database with ms access.hetviiIntroduction to database with ms access.hetvii
Introduction to database with ms access.hetvii
 
Database Management
Database ManagementDatabase Management
Database Management
 
Training MS Access 2007
Training MS Access 2007Training MS Access 2007
Training MS Access 2007
 
Rdbms
RdbmsRdbms
Rdbms
 
Database Concepts and Components
Database Concepts and ComponentsDatabase Concepts and Components
Database Concepts and Components
 
Introduction to ms access
Introduction to ms accessIntroduction to ms access
Introduction to ms access
 

Viewers also liked

Viewers also liked (11)

Datamodels & architecture
Datamodels & architectureDatamodels & architecture
Datamodels & architecture
 
Database Concept by Luke Lonergan
Database Concept by Luke LonerganDatabase Concept by Luke Lonergan
Database Concept by Luke Lonergan
 
Basic Concept of Database
Basic Concept of DatabaseBasic Concept of Database
Basic Concept of Database
 
2 database system concepts and architecture
2 database system concepts and architecture2 database system concepts and architecture
2 database system concepts and architecture
 
Chapter02
Chapter02Chapter02
Chapter02
 
Database language
Database languageDatabase language
Database language
 
Database management system basic, database, database management, learn databa...
Database management system basic, database, database management, learn databa...Database management system basic, database, database management, learn databa...
Database management system basic, database, database management, learn databa...
 
Fundamentals of Database system
Fundamentals of Database systemFundamentals of Database system
Fundamentals of Database system
 
Types dbms
Types dbmsTypes dbms
Types dbms
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Basic DBMS ppt
Basic DBMS pptBasic DBMS ppt
Basic DBMS ppt
 

Similar to Database Basics

Similar to Database Basics (20)

Chapter6 database connectivity
Chapter6 database connectivityChapter6 database connectivity
Chapter6 database connectivity
 
PATTERNS07 - Data Representation in C#
PATTERNS07 - Data Representation in C#PATTERNS07 - Data Representation in C#
PATTERNS07 - Data Representation in C#
 
SQL Prepared Statements Tutorial
SQL Prepared Statements TutorialSQL Prepared Statements Tutorial
SQL Prepared Statements Tutorial
 
Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
 
Lecture13
Lecture13Lecture13
Lecture13
 
Test Driven Database Development With Data Dude
Test Driven Database Development With Data DudeTest Driven Database Development With Data Dude
Test Driven Database Development With Data Dude
 
Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5
 
Chapter -7.pptx
Chapter -7.pptxChapter -7.pptx
Chapter -7.pptx
 
Spring framework DAO
Spring framework  DAOSpring framework  DAO
Spring framework DAO
 
Acutate - Using Stored Procedure
Acutate - Using Stored ProcedureAcutate - Using Stored Procedure
Acutate - Using Stored Procedure
 
unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
 
Jdbc
JdbcJdbc
Jdbc
 
Ado.net
Ado.netAdo.net
Ado.net
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
 
Ado
AdoAdo
Ado
 
Visual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetVisual Basic.Net & Ado.Net
Visual Basic.Net & Ado.Net
 
Spring jdbc dao
Spring jdbc daoSpring jdbc dao
Spring jdbc dao
 

More from ProdigyView

Installing Plug-ins
Installing Plug-insInstalling Plug-ins
Installing Plug-insProdigyView
 
Building An Application
Building An ApplicationBuilding An Application
Building An ApplicationProdigyView
 
Installing Applications
Installing ApplicationsInstalling Applications
Installing ApplicationsProdigyView
 
Video Content Management
Video Content ManagementVideo Content Management
Video Content ManagementProdigyView
 
Audio Content Management
Audio Content ManagementAudio Content Management
Audio Content ManagementProdigyView
 
File Content Management
File Content ManagementFile Content Management
File Content ManagementProdigyView
 
Email Configuration
Email ConfigurationEmail Configuration
Email ConfigurationProdigyView
 
HTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialHTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialProdigyView
 
HTML Forms Tutorial
HTML Forms TutorialHTML Forms Tutorial
HTML Forms TutorialProdigyView
 
Html Tags Tutorial
Html Tags TutorialHtml Tags Tutorial
Html Tags TutorialProdigyView
 
Video Conversion PHP
Video Conversion PHPVideo Conversion PHP
Video Conversion PHPProdigyView
 
Sending Email Basics PHP
Sending Email Basics PHPSending Email Basics PHP
Sending Email Basics PHPProdigyView
 
Tools ProdigyView
Tools ProdigyViewTools ProdigyView
Tools ProdigyViewProdigyView
 
Custom Validation PHP
Custom Validation PHPCustom Validation PHP
Custom Validation PHPProdigyView
 
Basic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPBasic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPProdigyView
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web CacheProdigyView
 
Javascript And CSS Libraries
Javascript And CSS LibrariesJavascript And CSS Libraries
Javascript And CSS LibrariesProdigyView
 
Implementing the Adapter Design Pattern
Implementing the Adapter Design PatternImplementing the Adapter Design Pattern
Implementing the Adapter Design PatternProdigyView
 
Intercepting Filters Design Pattern
Intercepting Filters Design PatternIntercepting Filters Design Pattern
Intercepting Filters Design PatternProdigyView
 

More from ProdigyView (20)

Installing Plug-ins
Installing Plug-insInstalling Plug-ins
Installing Plug-ins
 
Building An Application
Building An ApplicationBuilding An Application
Building An Application
 
Installing Applications
Installing ApplicationsInstalling Applications
Installing Applications
 
Video Content Management
Video Content ManagementVideo Content Management
Video Content Management
 
Audio Content Management
Audio Content ManagementAudio Content Management
Audio Content Management
 
File Content Management
File Content ManagementFile Content Management
File Content Management
 
Email Configuration
Email ConfigurationEmail Configuration
Email Configuration
 
HTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialHTML5 Tags and Elements Tutorial
HTML5 Tags and Elements Tutorial
 
HTML Forms Tutorial
HTML Forms TutorialHTML Forms Tutorial
HTML Forms Tutorial
 
Html Tags Tutorial
Html Tags TutorialHtml Tags Tutorial
Html Tags Tutorial
 
Video Conversion PHP
Video Conversion PHPVideo Conversion PHP
Video Conversion PHP
 
Sending Email Basics PHP
Sending Email Basics PHPSending Email Basics PHP
Sending Email Basics PHP
 
Tools ProdigyView
Tools ProdigyViewTools ProdigyView
Tools ProdigyView
 
Custom Validation PHP
Custom Validation PHPCustom Validation PHP
Custom Validation PHP
 
Basic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPBasic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHP
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web Cache
 
Javascript And CSS Libraries
Javascript And CSS LibrariesJavascript And CSS Libraries
Javascript And CSS Libraries
 
PHP Libraries
PHP LibrariesPHP Libraries
PHP Libraries
 
Implementing the Adapter Design Pattern
Implementing the Adapter Design PatternImplementing the Adapter Design Pattern
Implementing the Adapter Design Pattern
 
Intercepting Filters Design Pattern
Intercepting Filters Design PatternIntercepting Filters Design Pattern
Intercepting Filters Design Pattern
 

Recently uploaded

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

Database Basics

  • 1. Database Basics The power behind your web application
  • 2. Overview Objective Learn the basics of connecting to a database and executing sql queries ProdigyView. Requirements  A Mysql, Postrgesql or MSSQL database Estimated Time 10 Minutes
  • 3. Follow Along With Code Example 1. Download a copy of the example code at www.prodigyview.com/source. 2. Install the system in an environment you feel comfortable testing in. 3. Proceed to examples/database/Database.php
  • 4. A Brief Note About The Database Even though you can write a complete application in ProdigyView without using the database, it is more than likely that you are going to need the database at some point. The great feature that PVDatabase has is that it can connect to MySQL, PostgreSQL and MSSQL. In this tutorial we are going to learn:  Connecting to a database  Executing A Query  Iterating Through Results Current development is being done for MongoDB and SQLITE
  • 5. Disabling the Database If we are going to learn about truly manipulating the database, let’s first boot ProdigyView in a way that disables the database. Turn the database initialization off and loading the plug-ins off since they require a database connection. Boot System Disable Options
  • 6. Set a database Good, now with the database not initialized, we are going to configure a connection. Similar to the database configuration file, we are putting our database variables in an array.
  • 7. Time to Connect In our last slide, we created configuration paramters for a database we have access too. Next we are going to add the connection to PVDatabase and then connect to it. Name of the connection Connection Parameters Connect to a specified database. Use to switch between connections
  • 8. Create a table We are going to need a table to test with, so now lets create one. The process of creating tables is in another tutorial but we will give you a glimpse of it.
  • 9. Sanitizing Data When a user is inputting data, it is a general rule NOT to trust that data because it might contain malicious code that can wreak havoc on your database. Before inputting any information into your database through a query, sanitize it through makeSafe() function. Data after it is sanitized Data to be sanitized Data to be sanitized
  • 10. Executing 1. We have our connection set 2. We have a table and columns 3. We sanitized our information 4. We are ready for executing our first query. Insert query with our sanitized data Executes any query
  • 11. Again but get the id Great, we now know how to insert data into the database. But what if we want the id of the last entry? No problem. Let’s run our example again except this time we are going to execute using the return_last_insert_query(); The generated id The column that contains the auto incrementing id The table to return the column from
  • 12. A Closer Look The method return_last_insert_query(); takes the query and to additional arguments. The arguments are the column to be returned and the table to return the column from. These options are here because some databases require that there is a specified column or table to return the last generated id. If you want to make your application database agnostic, it is suggested that these parameters be used.
  • 13. Find Results – Row Count PVDatabase::query executes any query so it can be used for creating, updating, finding and deleting. But how to we get the results that are found? Not a problem. Let’s create a search querying and get row count. Count the rows in the result
  • 14. Find Results – Row Iteration That query in the previous slide will find the rows that we had previously inputted. Use the same $result with the method PVDatabase::fetchArray() to return an array of found data to iterate through.
  • 15. Challenge! Ok so we have the database basics down. So here is your challenge, it two parts 1. Add connections to multiple database and switch between those connections 2. Execute a select query on a database but use fetchFields() instead of fetchArray.
  • 16. The Not So Obvious 1. The function setConnection will close the connection to the current database and open a connection to a new one. 2. All the database methods are designed to automatically work with the set database 3. Other methods in ProdigyView, such as when creating content, will automatically sanitize data for you. 4. PVDatabase::makeSafe can also sanitize arrays
  • 17. Summary 1. Add a connection by using PVDatabase::addConnection() 2. Connection to a database using PVDatabase::setConnection() 3. Sanitize data before inserting into the database by using PVDatabase::makeSafe() 4. Execute a query using PVDatabase::query(); 5. Fetch results by using PVDatabase::fetchArray();
  • 18. API Reference For a better understanding of the database, visit the api by clicking on the link below. PVDatabase More Tutorials For more tutorials, please visit: http://www.prodigyview.com/tutorials www.prodigyview.com