This document provides an overview of a presentation on MySQL stored routines given in Amsterdam on June 16, 2007. The presentation covered:
1) A quick introduction to MySQL software products and professional services
2) An overview of MySQL stored routines, their language, and techniques for using them in PHP
3) Examples of stored routines, variables, and parameters
PHP Oracle Web Applications:
Best Practices and Caching Strategies
by Kuassi Mensah, Server Technologies, Oracle
Talk presented at PHP Barcelona Conference 2009.
2007 MySQL Conference and Expo 90 minute presentation specifically targeting Oracle Developers and DBAs. Topics included.
*DBA Tips, Tricks, Gotcha's & Tools
* Key Differences for Developers
* Migrating from Oracle to MySQL
MySQL's new Secure by Default Install -- All Things Open October 20th 2015Dave Stokes
One of the new features of MySQL 5.7 is enhanced security. This includes password rotation, lengthening the user name field, SSL encouragement, and much more. This session presented at All Things open 2015 and covers the changes in MySQL 5.7
MySQL Backup and Security Best PracticesLenz Grimmer
Slides of my talk about MySQL Backup and Security at phpDay in Verona, Italy:
http://www.phpday.it/site/phpday-2009/calendario-conferenze/canale-developers/mysql-backup-and-security-best-practices/
PHP Oracle Web Applications:
Best Practices and Caching Strategies
by Kuassi Mensah, Server Technologies, Oracle
Talk presented at PHP Barcelona Conference 2009.
2007 MySQL Conference and Expo 90 minute presentation specifically targeting Oracle Developers and DBAs. Topics included.
*DBA Tips, Tricks, Gotcha's & Tools
* Key Differences for Developers
* Migrating from Oracle to MySQL
MySQL's new Secure by Default Install -- All Things Open October 20th 2015Dave Stokes
One of the new features of MySQL 5.7 is enhanced security. This includes password rotation, lengthening the user name field, SSL encouragement, and much more. This session presented at All Things open 2015 and covers the changes in MySQL 5.7
MySQL Backup and Security Best PracticesLenz Grimmer
Slides of my talk about MySQL Backup and Security at phpDay in Verona, Italy:
http://www.phpday.it/site/phpday-2009/calendario-conferenze/canale-developers/mysql-backup-and-security-best-practices/
In this presentation I’ll be discussing the following beginner points to understanding and creating monitoring.
* Why Monitor?
* What’s the minimum to Monitor?
* How to monitor?
* Monitoring Software Options.
* How to use the most basic of monitoring to help
* The basics of graphing results
* The rule of Everything
* The important on Application metrics and timings
For a very little investment in time, simple monitoring can be in place, and I can guarantee it will be of benefit to any system.
The basis of monitoring are metrics that combined with application measurements can provide trending insights, bottleneck understanding and provide valuable feedback about your growing site.
MySQL and MariaDB though they share the same roots for replication .They support parallel replication , but they diverge the way the parallel replication is implemented.
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...Dave Stokes
MySQL is on the way and this presentation covers the new features, improved performance, and better admin that will come with 5.7. But there are some things that are changing that you need to know before you upgrade
Web application performance correlates with page views. Find out in this session how to maximize the performance of the OCI8 database extension to build fast, scalable web sites and attract users. Includes discussion of Oracle Database 11.2 and the upcoming PHP OCI8 1.4 extension.
MariaDB 10.5 binary install (바이너리 설치)
- 네오클로바 DB지원사업부
1. About MariaDB
1.1 MariaDB 개요
1.2 MariaDB as a R-DBMS
1.3 Open Source Database System
2. 설치
2.1 설치 기본 정보
2.2 설치 준비
2.3 MariaDB 설치
2.4 MariaDB 시작 / 접속 / 종료
2.5 추가 설정
MySql's NoSQL -- best of both worlds on the same disksDave Stokes
Get the best of both worlds -- SQL access and NoSQL access to the same data using the Memcached protocol. 9x faster than regular SQL, the Memcached protocol use allows applications to drink from the fire hose. Plus now your cache can be stored permanently. Easy and simple to implement.
"Disaster is inevitable" and "To move forward you must first backup" should be known to all software developers. This presentation will discuss all the options for your valuable data assets in MySQL, and highlight how to maintain site reliability of your data
Sjede li studenti u predavaonici prema slučajnom rasporedu?ilulic
Prezentacija rada "Sjede li studenti u predavaonici prema slučajnom rasporedu?" - autori Ileana Lulić, Ivor Ković, Bojan Basrak, Lidija Bilić-Zulle, Mladen Petrovečki. Rad je predstavila Ileana Lulić na 7. simpoziju Hrvatskog društva za medicinsku informatiku u Rijeci 21. listopada 2005. godine.
In this presentation I’ll be discussing the following beginner points to understanding and creating monitoring.
* Why Monitor?
* What’s the minimum to Monitor?
* How to monitor?
* Monitoring Software Options.
* How to use the most basic of monitoring to help
* The basics of graphing results
* The rule of Everything
* The important on Application metrics and timings
For a very little investment in time, simple monitoring can be in place, and I can guarantee it will be of benefit to any system.
The basis of monitoring are metrics that combined with application measurements can provide trending insights, bottleneck understanding and provide valuable feedback about your growing site.
MySQL and MariaDB though they share the same roots for replication .They support parallel replication , but they diverge the way the parallel replication is implemented.
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...Dave Stokes
MySQL is on the way and this presentation covers the new features, improved performance, and better admin that will come with 5.7. But there are some things that are changing that you need to know before you upgrade
Web application performance correlates with page views. Find out in this session how to maximize the performance of the OCI8 database extension to build fast, scalable web sites and attract users. Includes discussion of Oracle Database 11.2 and the upcoming PHP OCI8 1.4 extension.
MariaDB 10.5 binary install (바이너리 설치)
- 네오클로바 DB지원사업부
1. About MariaDB
1.1 MariaDB 개요
1.2 MariaDB as a R-DBMS
1.3 Open Source Database System
2. 설치
2.1 설치 기본 정보
2.2 설치 준비
2.3 MariaDB 설치
2.4 MariaDB 시작 / 접속 / 종료
2.5 추가 설정
MySql's NoSQL -- best of both worlds on the same disksDave Stokes
Get the best of both worlds -- SQL access and NoSQL access to the same data using the Memcached protocol. 9x faster than regular SQL, the Memcached protocol use allows applications to drink from the fire hose. Plus now your cache can be stored permanently. Easy and simple to implement.
"Disaster is inevitable" and "To move forward you must first backup" should be known to all software developers. This presentation will discuss all the options for your valuable data assets in MySQL, and highlight how to maintain site reliability of your data
Sjede li studenti u predavaonici prema slučajnom rasporedu?ilulic
Prezentacija rada "Sjede li studenti u predavaonici prema slučajnom rasporedu?" - autori Ileana Lulić, Ivor Ković, Bojan Basrak, Lidija Bilić-Zulle, Mladen Petrovečki. Rad je predstavila Ileana Lulić na 7. simpoziju Hrvatskog društva za medicinsku informatiku u Rijeci 21. listopada 2005. godine.
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL SupportMysql User Camp
This slide was presented at Mysql User Camp Event on 20-June-14 at Oracle bangalore. This presentation gives a good insight about New Features in Mysql 5.7 DMR 4 and Nosql Support in Mysql.
MySQL High Availability Solutions - Avoid loss of service by reducing the r...Olivier DASINI
MySQL High Availability Solutions
Avoid loss of service by reducing the risk of failures
MySQL InnoDB Cluster
Collection of products that work together to provide a complete High Availability solution for MySQL
MySQL InnoDB ReplicaSet
Administer a set of MySQL instances running asynchronous replication
MySQL NDB Cluster
A high-availability, high-redundancy version of MySQL adapted for the distributed computing environment
Nesta apresentação venceremos os obstáculos comuns para iniciar o desenvolvimento em Java usando corretamente o MySQL como banco de dados. O MySQL é o banco de dados open source mais popular do mundo, usado em grandes sites como Facebook, Youtube, Twitter, Yahoo, Globo.com etc. Abordaremos tópicos como: baixar e instalar um servidor MySQL para desenvolvimento, preparar o banco de dados para uso com JDBC, escrever e testar seus primeiros programas Java com MySQL e funcionalidades específicas do driver Connector/J para um desenvolvimento e implantação mais eficiente.
Starting with MySQL 5.7.12 we introduced a new plugin to use MySQL as a Document Store. This presentation gives an overview of current features and plans going forward.
MySQL 8.0 is the latest Generally Available version of MySQL. This session will give a brief introduction to MySQL 8.0 and help you upgrade from older versions, understand what utilities are available to make the process smoother and also understand what you need to bear in mind with the new version and considerations for possible behaviour changes and solutions. It really is a simple process.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
DPC2007 MySQL Stored Routines for PHP Developers (Roland Bouman)
1. Amsterdam, June 16 2007
● MySQL: Quick Introduction
● MySQL Stored Routines for PHP developers
● Questions and Discussion
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 1
2. Roland Bouman (rpbouman.blogspot.com)
Certification Developer
MySQL AB, Leiden
● MySQL Community Contributor since 2005
● Joined MySQL AB in July 2006
● Certification Developer:
● MySQL 5.1 Cluster DBA exam (CMCDBA)
● MySQL Associate exam (CMA)
● Attained:
● CMDEV
● CMDBA
● Formerly: Consultant & Application Developer
(mostly Oracle, some MS SQL)
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 2
3. Amsterdam, June 16 2007
● MySQL: Quick Introduction
● MySQL Stored Routines for PHP developers
● Questions and Discussion
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 3
4. MySQL: Quick Introduction
● MySQL Software Products
● RDBMS (Database)
● Monitoring and Advisory Service
● Drivers and APIs
● Client (GUI) Tools & Utilities
● MySQL Professional Services
● Technical Support
● Consulting
● Training
● Certification
● Indemnification
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 4
5. MySQL Open Source RDBMS Products
● Generally Available, Stable Releases
● MySQL 5.0 Server Community Edition
● Patches from community
● MySQL 5.0 Server Enterprise Edition
● Stablility and Robustness, Early Bugfixes
● Monitoring and Advisory Service
● Binaries
● Development Releases:
● MySQL 5.1 (New: Events, Partitioning)
● MySQL 6.0 (New: Falcon)
● Other RDBMS Products:
● MySQL Cluster / Carrier Grade Edition
● Embedded
● MaxDB (SAP Certified)
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 5
6. MySQL Monitoring and Advisory Service
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 6
7. MySQL Drivers and APIs
● For PHP
● ext/mysql: “MySQL Functions”
● ext/mysqli: “MySQL Improved Extension”
● mysqlnd: “MySQL native driver for PHP”
● Beta 5.
● Built Into PHP 5; PHP 6
● Replaces libmysql
● Other:
● ODBC: Connector/ODBC
● JDBC: Connector/J
● ADO.NET: Connector/.NET
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 7
8. Amsterdam, June 16 2007
● MySQL: Quick Introduction
● MySQL Stored Routines for PHP developers
● Questions and Discussion
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 8
9. MySQL Stored Routines
● Overview of MySQL Stored Routines
● MySQL Stored Routine Language
● PHP Techniques
● Use cases
● Best Practices
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 9
10. MySQL Stored Routines
● Overview of MySQL Stored Routines:
● Terminology, Purpose, Application
● MySQL Stored Routine Language
● Block Structure, Parameters and Variables, Flow Control
Constructs, SQL inside stored routines.
● PHP Techniques
● Creating and Calling Stored Procedures, Processing
Result set, Handling Multiple Result sets.
● Use cases
● Best Practices
● What to do on the client, and what on the server
● What to do in PHP, and what in Stored Routines.
● Performance: how MySQL Stored Routines can help or
hurt performance.
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 10
11. MySQL Stored Routines: Overview
● Programs as Database Schema Objects
● Executed in-process with the Database
● Types of Stored Routines:
● Procedures
● Functions
● Triggers
● Events (Temporal triggers; new in MySQL 5.1)
● Language:
● Subset of Standard SQL:2003 SQL/PSM
● Procedural, Block structured
● Do not confuse with User Defined Functions (UDF)!
● Available as of MySQL 5.0 (October 2005)
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 11
12. MySQL Stored Routine Types: Overview
● Stored Procedures & Functions
● Encapsulate tasks or Calculations for reuse
● Single point of definition for Business Logic
● Source Safely stored and backed up
● Added layer of Security
● Triggers
● Data-Driven
● Enforce Data quality through Basic validation
● Enforce complex Business Rules
● Automatically Update Aggregate tables
● Events (MySQL Server 5.1 beta)
● Schedule Code Execution in time.
● Use instead of cron or windows event scheduler
● Automatically Update Aggregate tables
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 12
13. MySQL Stored Routines: Purpose / Advantages
● Performance
● Save network roundtrips, lower latency
● Portability and Reuse
● Single point of definition
● Reusable from many application contexts
● Security
● DEFINER versus INVOKER
● Grant only Execution Privilege
● Ease of Maintenance
● Code stored in the database
● Browse using information_schema database
● 'Headless' administrative tasks
● No additional runtime environment required
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 13
14. MySQL Stored Routines: Caveat / Disadvantages
● Performance
● Overhead may result in higher latency
● Increased usage of database server computing power may
negatively affect throughput
● Portability and Reuse
● Which point of view?
● Database portability ?
● Or Application portability?
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 14
15. MySQL Stored Routines
● Overview of MySQL Stored Routines:
● Terminology, Purpose, Application
● MySQL Stored Routine Language
● Block Structure, Parameters and Variables, Flow Control
Constructs, SQL inside stored routines.
● PHP Techniques
● Creating and Calling Stored Procedures, Processing
Result set, Handling Multiple Result sets.
● Use cases
● Best Practices
● What to do on the client, and what on the server
● What to do in PHP, and what in Stored Routines.
● How MySQL Stored Routines can help or hurt
performance.
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 15
16. MySQL Stored Routine Language
● Subset of Standard SQL “Persistent Stored
Modules” (SQL/PSM)
● Procedural constructs with embedded SQL
● Parameters and (Local) variables
● Manipulate values
● Statement Sequence
● execute statements in order
● Choice
● conditionally execute a particular sequence
● Repetition
● execute a particular sequence multiple times
● A bit like Pascal with embedded SQL statements
● Valid inside all stored routine types
● Can be mixed with most SQL statements
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 16
17. Creating a MySQL Stored Procedure
• Prerequisite: CREATE ROUTINE and ALTER ROUTINE
privileges
CREATE PROCEDURE sp_hello(
p_who VARCHAR(32)
)
SELECT CONCAT('Hello, ',v_what,'!!');
DDL statement
• CREATE PROCEDURE
• Created in the current schema (= database)
Name (sp_hello) must be unique with in the
•
schema, may be qualified (my_db.sp_hello)
Parameter (p_who): IN parameter by default
•
• Procedure body is one single statement, in this
case, an ordinary SQL SELECT statement.
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 17
18. Calling a MySQL Stored Procedure
• Prerequisite: EXECUTE ROUTINE privilege
CALL sp_hello('PHP');
statement
• CALL
• Name identifies the procedure within the
schema, and maybe qualified:
CALL my_schema.sp_hello('PHP')
• Must pass a parameter value
Result:
Hello, PHP!
• Result set returned to the client
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 18
19. Generic Statement Sequence: BEGIN...END
CREATE PROCEDURE sp_greating(
p_who VARCHAR(32)
, p_what VARCHAR(32)
)
BEGIN
SELECT CONCAT('Hello ', p_who);
SELECT CONCAT(p_what,'!');
END
is a compound statement; it may
• BEGIN...END
contain multiple other statements.
• Contained statements executed Sequentially (in
order of appearance)
• (Sidenote: 2 result sets are returned to the client)
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 19
20. Variables and Parameters
CREATE PROCEDURE sp_fibonacci(
INOUT p_m INT, INOUT p_n INT, OUT p_s DOUBLE)
BEGIN
DECLARE v_m INT DEFAULT COALESCE(p_m,0);
DECLARE v_n INT DEFAULT COALESCE(p_n,1);
SET p_m := v_n; single assignment
SET p_n := v_m + v_n multiple
, p_s := p_m/p_n; assignments
SELECT p_m, p_n, p_s;
END;
and INOUT parameters
• IN, OUT
• DECLARE local variables, optionally assign a default value
• Use SET to assign values to one or more variables
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 20
22. Variable Scope / Visibility
BEGIN
DECLARE v_script, v_http VARCHAR(32);
SET v_script := 'PHP', v_http := 'Apache';
SELECT v_script, v_http;
BEGIN
DECLARE v_http VARCHAR(32);
SET v_http := 'lighttpd';
SELECT v_script, v_http;
END;
SELECT v_script, v_http;
END;
• Variables are visible only inside the declaring block
• Nearest Scope: inner declarations mask outer ones
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 22
23. Choice Constructs
● Compound statements
● IF...END IF statement
● Simple test of a single condition
● Conditionally start a sequence of statements (branch)
● Optionally, chooses between two branches
Don't confuse with the IF() function!
●
● CASE...END CASE statement
● Conditionally starts one out of multiple branches
● Simple CASE statement
● Just like switch in PHP
● Searched CASE statement
● Just like nested if...elseif...else in PHP
● Don't confuse with the CASE..END expression!
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 23
24. Syntax: IF...END IF
● Tests condition, branches when TRUE
● Conditional branch can contain a sequence
//main, unconditional branch
IF <condition> THEN
<statements> “true” branch
END IF;
● Optionally, include a branch for the other case:
IF <condition> THEN
<statements> ”true” branch
ELSE
<statements> ”false” branch
END IF;
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 24
25. IF statement vs IF function
● An IF statement chooses between sequences of
statements
IF CURRENT_TIME < '12:00:00' THEN
SELECT 'Good Morning';
ELSE
SELECT 'Good Afternoon';
END IF;
function chooses between expressions
● IF
SELECT IF(CURRENT_TIME < '12:00:00'
, 'Good Morning'
, 'Good Afternoon'
);
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 25
26. Syntax: Simple CASE..END CASE
● Evaluate expression and compare
● Conditional branch can contain a sequence
● Optional ELSE branch
● Just like switch...case in PHP
CASE <expression>
WHEN <expression1> THEN
<statements>
WHEN <expression2> THEN
<statements>
ELSE
<statements>
END CASE;
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 26
27. Syntax: Searched CASE..END CASE
● Search first TRUE condition, then branch
● Conditional branch can contain a sequence
● Optional ELSE branch
● Just like if...elsif...else in PHP
CASE
WHEN <condition>
THEN <statements>
WHEN <expression>
THEN <statements>
ELSE
<statements>
END CASE;
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 27
28. Repetition
● Unstructured Loop
● No explicit logic to end the loop
LOOP
<statement>
END LOOP;
● Structured
● Logic to end the loop is part of the construct
REPEAT
WHILE
<statement>
<condition>
UNTIL
DO
<condition>
<statement>
END REPEAT;
END WHILE;
● Iterate:
● Leave: exit the current block
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 28
29. Triggers
CREATE
[DEFINER = { <username> | CURRENT_USER }]
TRIGGER <triggername>
{BEFORE | AFTER}
{INSERT | UPDATE | DELETE}
ON <tablename>
FOR EACH ROW
<singlestatement>
● Automatically executed in response to row-
level events occurring on table
● Can refer to OLD and NEW pseudo-records
● INSERT: NEW
● DELETE: OLD
both OLD and NEW
● UPDATE:
● Executed as part of transaction
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 29
30. Event Scheduler (Temporal Triggers)
● New in MySQL 5.1
● Automatically executed according to time
schedule
● Can be recurring
● Can be scheduled to start in the future
● Can be instructed to clean itself up
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 30
31. MySQL Stored Routines
● Overview of MySQL Stored Routines:
● Terminology, Purpose, Application
● MySQL Stored Routine Language
● Block Structure, Parameters and Variables, Flow Control
Constructs, SQL inside stored routines.
● PHP Techniques
● Creating and Calling Stored Procedures, Processing
Result Set, Handling Multiple Result Sets.
● Use cases
● Best Practices
● What to do on the client, and what on the server
● What to do in PHP, and what in Stored Routines.
● How MySQL Stored Routines can help or hurt
performance.
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 31
32. PHP and MySQL Stored Routines
● Two relevant PHP extensions
● MySQL Functions (ext/mysql)
● CREATE PROCEDURE and CALL work fine
● Just use the PHP function mysql_query()
● However, obtaining a result set is impossible
● MySQL Improved extension (ext/mysqli)
● use mysqli_query() for one result set
● For multiple resultsets, use
mysqli_multi_query()
●
mysqli_use_result()
●
mysqli_store_result()
●
mysqli_next_result()
●
mysqli_more_results()
●
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 32
33. mysql_query() and Stored Routines
<?php
$db = mysql_connect($host,$usr,$pwd);
mysql_select_db('test',$db);
$result = mysql_query(
quot;CALL sp_hello('PHP')quot;,$db
);
$num_rows = mysql_affected_rows($db);
echo '<br/>num: ', $num_rows;
echo '<br/>msg: ', mysql_error($db);
echo '<br/>no: ', mysql_errno($db);
?>
num: 1
msg: PROCEDURE test.sp_hello can't return
a result set in the given context
no: 1312
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 33
34. mysqli_query() and Stored Routines
<?php
$db = mysqli_connect($host,$usr,$pwd);
$db>select_db('test');
$result = mysqli_query(
$db,quot;CALL sp_hello('PHP')quot;
);
$row = mysqli_fetch_row($result);
echo $row[0];
?>
Hello, PHP!
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 34
35. Handling Multiple result sets
<?php
$db = mysqli_connect($host,$usr,$pwd);
$db>select_db('test');
$db>multi_query(
quot;CALL sp_greating('PHP','Good Morning')quot;
);
while($result = $db>store_result()) {
while ($row = $result>fetch_row()) {
echo $row[0];
}
$result>close();
$db>next_result();
}
?>
Hello PHP, Good Morning!
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 35
36. MySQL Stored Routines
● Overview of MySQL Stored Routines:
● Terminology, Purpose, Application
● MySQL Stored Routine Language
● Block Structure, Parameters and Variables, Flow Control
Constructs, SQL inside stored routines.
● PHP Techniques
● Creating and Calling Stored Procedures, Processing
Result set, Handling Multiple Result sets.
● Use Cases
● Best Practices
● What to do on the client, and what on the server
● What to do in PHP, and what in Stored Routines.
● How MySQL Stored Routines can help or hurt
performance.
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 36
37. MySQL Stored Routine Use Cases
● Stored Procedures
● subtypes and vertical partitioning
● data intensive transformation
● Stored Functions
● domain specific calculations
● data transformation
● Triggers
● Auditing
● Automatically Aggregate tables
● Events
● Logging status
● Updating aggregate tables “Materialized views”
● ETL processes
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 37
38. MySQL Stored Routines
● Overview of MySQL Stored Routines:
● Terminology, Purpose, Application
● MySQL Stored Routine Language
● Block Structure, Parameters and Variables, Flow Control
Constructs, SQL inside stored routines.
● PHP Techniques
● Creating and Calling Stored Procedures, Processing
Result set, Handling Multiple Result sets.
● Use Cases
● Best Practices
● What to do on the client, and what on the server
● What to do in PHP, and what in Stored Routines.
● How MySQL Stored Routines can help or hurt
performance.
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 38
39. MySQL Stored Procedures: Best Practices
● Use pure SQL when you can
● Use stored procedures for data-intensive
operations
● Don't use stored procedures for complex
computation
● Don't use stored procedures for single layer
encapsulation
● Simple CRUD layers don't scale
● Stored Procedure should add significant functionality
● Return multiple result sets from stored procedures
to reduce network roundtrips
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 39
40. MySQL Triggers: Best Practices
● Use triggers to enforce integrity of data
● Using triggers does not mean the application can
forget about validation
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 40
41. Amsterdam, June 16 2007
● MySQL: Quick Introduction
● MySQL Stored Routines for PHP developers
● Questions and Discussion
Copyright 2007 MySQL AB The World’s Most Popular Open Source Database 41