13
FUNCTIONS AND STORED PROCEDURES & FUNCTIONS AND PROTECTING A DB AND PHP (Chapters 9, 15, 18)

Functions And Stored Procedures & functions and Protecting a DB AND PHP

  • Upload
    nani

  • View
    43

  • Download
    0

Embed Size (px)

DESCRIPTION

Functions And Stored Procedures & functions and Protecting a DB AND PHP. ( C hapters 9, 15, 18). Canned String Functions. Concatenate Length of a string Removing leading or trailing spaces Finding string substrings Transform string to upper or lower case Reversing a string - PowerPoint PPT Presentation

Citation preview

Page 1: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

FUNCTIONS ANDSTORED PROCEDURES & FUNCTIONS AND PROTECTING A DBAND PHP

(Chapters 9, 15, 18)

Page 2: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

Canned String Functions• Concatenate• Length of a string• Removing leading or trailing spaces• Finding string substrings• Transform string to upper or lower case• Reversing a string• Insert a substring into a string• Right or left padding of a string with a character• Etc.

Page 3: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

Canned Numerical Functions• Round• Truncate• Absolute value• Square root• Random value• Etc.

Page 4: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

Dates and Times• Now – local date and time from clock• Current timestamp• Currant date• Current time• Extract second, minute, hour, etc.,, from a date• Formatting dates• Adding intervals to dates• Subtract intervals from dates• Returning elapsed period length• Etc.

Page 5: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

Specialized Functions• IF (testing an expression for true)• IFNULL (test two expressions and return first or second

based on which is non-null)• COALESCE (test a list of expressions and return first non-

null)

Page 6: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

Two ways to use SQL with an Application

• Dynamic SQL• Embedded SQL• Making calls to an SQL based DB

Page 7: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

Dynamic SQL• SQL code can be generated at runtime based on

conditions found by the Host application• In particular, to create the appropriate WHERE clauses• The SQL code is put into a Host application string variable• You can use dynamic SQL within a stored procedure

Page 8: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

EMBEDDED SQL• SQL is placed inside Host application code• The SQL is processed in a first compilation phase• SQL application uses cursors and INTO statements to

pass values to Host application

Page 9: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

Connecting to a DB• PHP:

• mysqli (the i is for improved)• or PDO (PHP Data Objects)

• Java: there are a set of drivers for the various relational databases, including MySQL• The JDBC drivers are very popular and a lot of GUIs use them

• .NET driver

Page 10: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

Protecting a MySQL DB• Create and delete databases• Grant specific access rights to groups of users

• Insert, Delete, Select rights on databases• Administration and other users• You can limit a user to access a DB only from a certain IP address

• Separate access rights for altering a schema• Create DBs• Add tables• Change tables• Create views• Create indices• Create triggers

Page 11: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

PHP and MySQL

Web Server Database Server

E-mail Server

The Internet

`

Client

`

Client

Page 12: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

Continued

Web Server

PHPScript

Database Server

HTTP request

HTTP response`

Web Browser

Page 13: Functions And Stored Procedures & functions  and Protecting a DB AND PHP

The MVC pattern

`

Browser

Controllerindex.php

Viewproduct_list.phpproduct_add.php

database_error.php

Modeldatabase.php

product_db.phpcategory_db.php

Data store

HTTPrequest

HTTPresponse