SlideShare une entreprise Scribd logo
1  sur  54
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Session Title: Develop PHP Applications with MySQL X DevAPI
• Conference: Oracle Code One
• Session Type: Developer Session
• Session ID: DEV5981
• Presenter: David Stokes
Confidential – Oracle Internal/Restricted/Highly Restricted
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Develop PHP Applications
With The MySQL X DevAPI
Dave Stokes
MySQL Community Manager
Oracle Corporation
October 24, 2018
David.Stokes@Oracle.com
@Stoker
Confidential – Oracle Internal/Restricted/Highly Restricted
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The preceding is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
Confidential – Oracle Internal/Restricted/Highly Restricted
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Who Am I
Dave Stokes
MySQL Community Manager
@Stoker
David.Stokes @ Oracle.com
Slideshare.net/davidmstokes
My new book ->
Confidential – Oracle Internal/Restricted/Highly Restricted 4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
So What Is DEV5981 All About?
Agenda
Confidential – Oracle Internal/Restricted/Highly Restricted 5
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Agenda
1. X Devapi
– What is it?
– MySQL Without the SQL
– MySQL Document Store
2. Installation of PECL Extension
– Where to get mysql_xdevapi and other needed software
– Build the PECL Extension
3. Coding
– Examples, Examples, and a few more Examples
Confidential – Oracle Internal/Restricted/Highly Restricted 6
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
No Code Changes Needed for Cluster Operations
The code that is needed to connect to a MySQL document store looks a lot like
the traditional MySQL connection code, but now applications can establish logical
sessions to MySQL server instances running the X Plugin.
Sessions are produced by the mysqlx factory, and the returned Sessions can
encapsulate access to one or more MySQL server instances running X Plugin.
Applications that use Session objects by default can be deployed on both single
server setups and database clusters with no code changes.
7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Session Creation
Create a Session using the mysqlx.getSession(connection) method. You
pass in the connection parameters to connect to the MySQL server, such as the
hostname, user and so on, very much like the code in one of the classic APIs.
The connection parameters can be specified as either a URI type string, for
example user:@localhost:33060, or as a data dictionary, for example
{user: myuser, password: mypassword, host: example.com,
port: 33060}
8
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Protocol
9
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
X DevAPI
Part I
Confidential – Oracle Internal/Restricted/Highly Restricted 10
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
X Devapi -> What is it?
User Guide :
https://dev.mysql.com/doc/x-devapi-userguide/en/
Confidential – Oracle Internal/Restricted/Highly Restricted
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
X Devapi
The X DevAPI wraps powerful concepts in a simple API.
● A new high-level session concept enables you to write code
that can transparently scale from single MySQL Server to a
multiple server environment.
● Read operations are simple and easy to understand.
● Non-blocking, asynchronous calls follow common host
language patterns.
Confidential – Oracle Internal/Restricted/Highly Restricted
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The X DevAPI introduces a new, modern
and easy-to-learn way to work with your data.
● Documents are stored in Collections and have their
dedicated CRUD operation set.
● Work with your existing domain objects or generate code
based on structure definitions for strictly typed languages.
● Focus is put on working with data via CRUD operations.
● Modern practices and syntax styles are used to get away
from traditional SQL-String-Building.
Confidential – Oracle Internal/Restricted/Highly Restricted
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Simple Summation
You no longer have to embed ugly
strings of Structured Query
Language (SQL) code in your
beautiful PHP Code.
14
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The X DevAPI and Create Read,
Update, and Delete (CRUD) operations.
CRUD operations are available as methods, which operate on Schema objects.
The available Schema objects consist of
Collection objects, containing Documents,
or
Table objects consisting of rows and Collections containing Documents.
Confidential – Oracle Internal/Restricted/Highly Restricted 15
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The following table shows the available CRUD operations for both Collection and
Table objects.
16
Operation Document Relational
Create Collection.add() Table.insert()
Read Collection.find() Table.select()
Update Collection.modify() Table.update()
Delete Collection.remove() Table.delete()
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Database Object - Class Diagram
17
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Method Chaining
The X DevAPI supports a number of modern practices
to make working with CRUD operations easier and to
fit naturally into modern development environments.
This section explains how to use method chaining
instead of working with SQL strings of JSON
structures.
18
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Synchronous versus Asynchronous Execution
Traditionally, many MySQL drivers used a synchronous approach
when executing SQL statements. This meant that operations such
as opening connections and executing queries were blocked until
completion, which could take a long time. To allow for parallel
execution, a developer had to write a multithreaded application.
Any MySQL client that supports the X Protocol can provide
asynchronous execution, either using callbacks, Promises,
or by explicitly waiting on a specific result at the moment in time
when it is actually needed.
19
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Working with Collections
Working with collections of documents is straight forward when
using the X DevAPI. The following examples show the basic
usage of CRUD operations when working with documents.
20
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 21
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 22
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 23
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 24
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
MySQL X DevAPI PECL Extension
Agenda
Confidential – Oracle Internal/Restricted/Highly Restricted 25
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
An example installation procedure on Ubuntu 18.04 with PHP 7.2:
// Dependencies
$ apt install build-essential libprotobuf-dev libboost-dev openssl protobuf-compiler
// PHP with the desired extensions; php7.2-dev is required to compile
$ apt install php7.2-cli php7.2-dev php7.2-mysql php7.2-pdo php7.2-xml
// Compile the extension
$ pecl install mysql_xdevapi
26
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The pecl install command does not enable PHP extensions (by default) and enabling
PHP extensions can be done in several ways. Another PHP 7.2 on Ubuntu 18.04
example:
// Create its own ini file
$ echo "extension=mysql_xdevapi.so" > /etc/php/7.2/mods-
available/mysql_xdevapi.ini
// Use the 'phpenmod' command (note: it's Debian/Ubuntu specific)
$ phpenmod -v 7.2 -s ALL mysql_xdevapi
// A 'phpenmod' alternative is to manually symlink it
// $ ln -s /etc/php/7.2/mods-available/mysql_xdevapi.ini
/etc/php/7.2/cli/conf.d/20-mysql_xdevapi.ini
27
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Check to make sure MySQL Modules loaded
php -m | grep mysql
mysql_xdevapi
mysqli
mysqlnd
PDO_mysql
28
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RPM users
The only way currently is to load all the needed software and build PHP from
scratch.
And yes, that is going to be corrected.
29
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Examples in PHP
So what does the code look like?!?!
Confidential – Oracle Internal/Restricted/Highly Restricted 30
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
X DevAPI -- Lots of similarities to mysqli and PDO
1. Connect to server
a. Username, Password, Port, schema, encodings, etc.
2. Send Query
3. Get Results
4. Disconnect
31
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
QUICK Review of PHP/MySQL APIs
So you have three choices now...
32
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Mysqli - replaces old, deprecated mysql interface
<?php
$mysqli = new mysqli("example.com", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " .
$mysqli->connect_error;
}
if (!$mysqli->query("DROP TABLE IF EXISTS test") ||
!$mysqli->query("CREATE TABLE test(id INT)") ||
!$mysqli->query("INSERT INTO test(id) VALUES (1)")) {
echo "Table creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
?>
Confidential – Oracle Internal/Restricted/Highly Restricted 33
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
PDO
Confidential – Oracle Internal/Restricted/Highly Restricted 34
<?php
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
$stmt = $db->prepare('select * from foo',
array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
} else {
die("my application only works with mysql;
I should use $stmt->fetchAll() instead");
}
?>
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
X Devapi Connection
<?php
$session =
mysql_xdevapigetSession("mysqlx://user:password@host");
if ($session === NULL) {
die("Connection could not be established");
}
// ... use $session
?>
35
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
So Lets Walk Through a X DevAPI Example
:-)
36
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Create a schema and a collection
$schema = $session->createSchema("test");
$collection = $schema->createCollection("example");
37
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Create Some Data
$marco = [
"name" => "Marco",
"age" => 19,
"job" => "Programmer"
];
$mike = [
"name" => "Mike",
"age" => 39,
"job" => "Manager"
];
38
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Store Data
$schema = $session->getSchema("test");
$collection = $schema->getCollection("example");
$collection->add($marco, $mike)->execute();
var_dump($collection->find("name ='Mike'")->execute()->fetchOne());
39
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Fetch Data
$result = $collection->find()->execute());
foreach ($result as $doc) {
echo "${doc["name"]} is a ${doc["job"]}.n";
}
40
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Yet More Examples!
Subtitle
Confidential – Oracle Internal/Restricted/Highly Restricted 41
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 42
#!/usr/bin/php
<?PHP
// Connection parameters
$user = 'root';
$passwd = 'S3cret#';
$host = 'localhost';
$port = '33060';
$connection_uri = 'mysqlx://'.$user.':'.$passwd.'@'.$host.':'.$port;
echo $connection_uri . "n";
// Connect as a Node Session
$nodeSession = mysql_xdevapigetNodeSession($connection_uri);
// "USE world_x" schema
$schema = $nodeSession->getSchema("world_x");
// Specify collection to use
$collection = $schema->getCollection("countryinfo");
// SELECT * FROM world_x WHERE _id = "USA"
$result = $collection->find('_id = "USA"')->execute();
// Fetch/Display data
$data = $result->fetchAll();
var_dump($data);
?>
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 43
#!/usr/bin/php
<?PHP
// Connection parameters
$user = 'root';
$passwd = 'S3cret#';
$host = 'localhost';
$port = '33060';
$connection_uri = 'mysqlx://'.$user.':'.$passwd.'@'.$host.':'.$port;
echo $connection_uri . "n";
// Connect as a Node Session
$nodeSession = mysql_xdevapigetNodeSession($connection_uri);
// "USE world_x" schema
$schema = $nodeSession->getSchema("world_x");
// Specify collection to use
$collection = $schema->getCollection("countryinfo");
// SELECT * FROM world_x WHERE _id = "USA"
$result = $collection->find('_id = "USA"')->execute();
// Fetch/Display data
$data = $result->fetchAll();
var_dump($data);
?>
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 44
#!/usr/bin/php
<?PHP
// Connection parameters
$user = 'root';
$passwd = 'S3cret#';
$host = 'localhost';
$port = '33060';
$connection_uri = 'mysqlx://'.$user.':'.$passwd.'@'.$host.':'.$port;
echo $connection_uri . "n";
// Connect as a Node Session
$nodeSession = mysql_xdevapigetNodeSession($connection_uri);
// "USE world_x" schema
$schema = $nodeSession->getSchema("world_x");
// Specify collection to use
$collection = $schema->getCollection("countryinfo");
// SELECT * FROM world_x WHERE _id = "USA"
$result = $collection->find('_id = "USA"')->execute();
// Fetch/Display data
$data = $result->fetchAll();
var_dump($data);
?>
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 45
#!/usr/bin/php
<?PHP
// Connection parameters
$user = 'root';
$passwd = 'S3cret#';
$host = 'localhost';
$port = '33060';
$connection_uri = 'mysqlx://'.$user.':'.$passwd.'@'.$host.':'.$port;
echo $connection_uri . "n";
// Connect as a Node Session
$nodeSession = mysql_xdevapigetNodeSession($connection_uri);
// "USE world_x" schema
$schema = $nodeSession->getSchema("world_x");
// Specify collection to use
$collection = $schema->getCollection("countryinfo");
// SELECT * FROM world_x WHERE _id = "USA"
$result = $collection->find('_id = "USA"')->execute();
// Fetch/Display data
$data = $result->fetchAll();
var_dump($data);
?>
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 46
<?php
$uri = "mysqlx://root:XXX@localhost:33060/?ssl-mode=disabled";
$nodeSession = mysql_xdevapigetSession( $uri );
$schema = $nodeSession->createSchema( "testx" );
$coll = $schema->createCollection( "store" );
$result = $coll->add( '{ "product" : "iPhone X", "price":1000,
"stock" : 2 }' )->execute();
print 'The generated ID for the document is: ' . $result-
>getDocumentId() . PHP_EOL;
?>
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 47
$uri = "mysqlx://root:XXX@localhost:33060?ssl-mode=disabled";
$nodeSession = mysql_xdevapigetSession( $uri );
$schema = $nodeSession->createSchema( "testx" );
$coll = $schema->createCollection( "store" );
$result = $coll->add( '{ "product" : "iPhone X", "price":1000, "stock" : 2 }'
'{ "product" : "Nokia Y", "price":900, "stock" : 3,
"description": "A good mobile phone" }' )->execute();
$item_count = $result->getAffectedItemsCount();
print($item_count." documents has been added to the collection, printing ID's");
$ids = $result->getGeneratedIds();
for( $i = 0 ; $i < $item_count ; $i++ ) {
print("The document ID number ".$i." is ".$ids[$i].PHP_EOL);
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 48
//Add some documents, note that I'm providing the IDs myself
$res = $coll->add(
["_id" => "1", "name" => "Carlotta", "age" => 34, "job" => "Dentista"],
["_id" => "2", "name" => "Antonello", "age" => 45, "job" => "Tassinaro"],
["_id" => "3", "name" => "Mariangela", "age" => 32, "job" => "Attrice"],
["_id" => "4", "name" => "Antonio", "age" => 42, "job" => "Urologo"]
)->execute();
//Remove the document with ID 4
$coll->removeOne("4");
//Find all the entries for which the 'age' field is greater than 30
$res = $coll->find("age > 30")->execute();
//Fetch the entries
$data = $res->fetchAll();
//Print the results
for( $i = 0 ; $i < count( $data ) ; $i++ ) {
print($data[$i]["name"]." have more than 30 years!");
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 49
//Fill the collection with some documents
$coll->add('{"name": "Sakila", "age": 15, "job": "Programmer"}',
'{"name": "Sakila", "age": 17, "job": "Singer"}',
'{"name": "Sakila", "age": 18, "job": "Student"}',
'{"name": "Arnold", "age": 24, "job": "Plumber"}',
'{"name": "Robert", "age": 39, "job": "Manager"}')->execute();
//This modify operation will change the 'job' to 'Unemployed' for all
//the three Sakila in the collection
$coll->modify("name like 'Sakila'")->set("job", "Unemployed")->execute();
//Add a second job to Arnold, the field 'job' will now on be an array
//of two elements: 'Plumber' and 'Nursey'
$coll->modify("name like 'Arnold'")->arrayAppend('job','Nursey')->execute();
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
What About Relational Tables??
Yet More Examples!
50
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 51
<?php
$session = mysql_xdevapigetSession("mysqlx://root:secret@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")-
>execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam',
33)")->execute();
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
$row = $table->select('name', 'age')->execute()->fetchAll();
print_r($row);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 52
#!/bin/php
<?php
$session = mysql_xdevapigetSession("mysqlx://root:hidave@localhost:33060");
if ($session === NULL) {
die("Connection could not be established");
}
$schema = $session->getSchema("world");
$table = $schema->getTable("city");
$row = $table->select('Name','District')
->where('District like :district')
->bind(['district' => 'Texas'])
->execute()->fetchAll();
print_r($row);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Q/A
?
Confidential – Oracle Internal/Restricted/Highly Restricted 53
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 54
Slides posted to https://slideshare.net/davidmstokes
@stoker or David.Stokes @ Oracle.com

Contenu connexe

Tendances

Tendances (20)

JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
 
Open Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational DatabaseOpen Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational Database
 
Database basics for new-ish developers -- All Things Open October 18th 2021
Database basics for new-ish developers  -- All Things Open October 18th 2021Database basics for new-ish developers  -- All Things Open October 18th 2021
Database basics for new-ish developers -- All Things Open October 18th 2021
 
Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational database
 
Discover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQLDiscover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQL
 
Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my!
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
 
MySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentation
 
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
 
PNWPHP -- What are Databases so &#%-ing Difficult
PNWPHP -- What are Databases so &#%-ing DifficultPNWPHP -- What are Databases so &#%-ing Difficult
PNWPHP -- What are Databases so &#%-ing Difficult
 
MySQL's NoSQL -- Texas Linuxfest August 22nd 2015
MySQL's NoSQL  -- Texas Linuxfest August 22nd 2015MySQL's NoSQL  -- Texas Linuxfest August 22nd 2015
MySQL's NoSQL -- Texas Linuxfest August 22nd 2015
 
Confoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsConfoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & Histograms
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
MySQL 8.0 Operational Changes
MySQL 8.0 Operational ChangesMySQL 8.0 Operational Changes
MySQL 8.0 Operational Changes
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql Database
 
Breakthrough performance with MySQL Cluster (2012)
Breakthrough performance with MySQL Cluster (2012)Breakthrough performance with MySQL Cluster (2012)
Breakthrough performance with MySQL Cluster (2012)
 
Introduction to MySQL Document Store
Introduction to MySQL Document StoreIntroduction to MySQL Document Store
Introduction to MySQL Document Store
 
MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016
MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016
MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016
 
PHP Oracle
PHP OraclePHP Oracle
PHP Oracle
 

Similaire à Develop PHP Applications with MySQL X DevAPI

Similaire à Develop PHP Applications with MySQL X DevAPI (20)

20171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v120171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v1
 
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
 
PHP, The X DevAPI, and the MySQL Document Store Presented January 23rd, 20...
PHP,  The X DevAPI,  and the  MySQL Document Store Presented January 23rd, 20...PHP,  The X DevAPI,  and the  MySQL Document Store Presented January 23rd, 20...
PHP, The X DevAPI, and the MySQL Document Store Presented January 23rd, 20...
 
MySQL Connector/Node.js and the X DevAPI
MySQL Connector/Node.js and the X DevAPIMySQL Connector/Node.js and the X DevAPI
MySQL Connector/Node.js and the X DevAPI
 
Using MySQL Containers
Using MySQL ContainersUsing MySQL Containers
Using MySQL Containers
 
Connector/J Beyond JDBC: the X DevAPI for Java and MySQL as a Document Store
Connector/J Beyond JDBC: the X DevAPI for Java and MySQL as a Document StoreConnector/J Beyond JDBC: the X DevAPI for Java and MySQL as a Document Store
Connector/J Beyond JDBC: the X DevAPI for Java and MySQL as a Document Store
 
MySQL Shell: The DevOps Tool for MySQL
MySQL Shell: The DevOps Tool for MySQLMySQL Shell: The DevOps Tool for MySQL
MySQL Shell: The DevOps Tool for MySQL
 
Python And The MySQL X DevAPI - PyCaribbean 2019
Python And The MySQL X DevAPI - PyCaribbean 2019Python And The MySQL X DevAPI - PyCaribbean 2019
Python And The MySQL X DevAPI - PyCaribbean 2019
 
OUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source CodeOUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source Code
 
MySQL Document Store and Node.JS
MySQL Document Store and Node.JSMySQL Document Store and Node.JS
MySQL Document Store and Node.JS
 
Servlet 4.0 JavaOne 2017
Servlet 4.0 JavaOne 2017Servlet 4.0 JavaOne 2017
Servlet 4.0 JavaOne 2017
 
Node.js and Oracle Database: New Development Techniques
Node.js and Oracle Database: New Development TechniquesNode.js and Oracle Database: New Development Techniques
Node.js and Oracle Database: New Development Techniques
 
MySQL in Oracle environment : Quick start guide for Oracle DBA (Part 1)
MySQL in Oracle environment : Quick start guide for Oracle DBA (Part 1)MySQL in Oracle environment : Quick start guide for Oracle DBA (Part 1)
MySQL in Oracle environment : Quick start guide for Oracle DBA (Part 1)
 
20191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv120191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv1
 
MySQL 8.0 - What's New ?
MySQL 8.0 - What's New ?MySQL 8.0 - What's New ?
MySQL 8.0 - What's New ?
 
Node.js and the MySQL Document Store
Node.js and the MySQL Document StoreNode.js and the MySQL Document Store
Node.js and the MySQL Document Store
 
GraphPipe - Blazingly Fast Machine Learning Inference by Vish Abrams
GraphPipe - Blazingly Fast Machine Learning Inference by Vish AbramsGraphPipe - Blazingly Fast Machine Learning Inference by Vish Abrams
GraphPipe - Blazingly Fast Machine Learning Inference by Vish Abrams
 
MySQL Connector/J in the Making of Modern Applications
MySQL Connector/J in the Making of Modern ApplicationsMySQL Connector/J in the Making of Modern Applications
MySQL Connector/J in the Making of Modern Applications
 
MySQL Innovation from 5.7 to 8.0
MySQL Innovation from 5.7 to 8.0MySQL Innovation from 5.7 to 8.0
MySQL Innovation from 5.7 to 8.0
 
MySQL Innovation: from 5.7 to 8.0
MySQL Innovation:  from 5.7 to 8.0MySQL Innovation:  from 5.7 to 8.0
MySQL Innovation: from 5.7 to 8.0
 

Plus de Dave Stokes

Plus de Dave Stokes (20)

Locking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxLocking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptx
 
Linuxfest Northwest 2022 - MySQL 8.0 Nre Features
Linuxfest Northwest 2022 - MySQL 8.0 Nre FeaturesLinuxfest Northwest 2022 - MySQL 8.0 Nre Features
Linuxfest Northwest 2022 - MySQL 8.0 Nre Features
 
MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022
 
Windowing Functions - Little Rock Tech fest 2019
Windowing Functions - Little Rock Tech fest 2019Windowing Functions - Little Rock Tech fest 2019
Windowing Functions - Little Rock Tech fest 2019
 
The Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesThe Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL Databases
 
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
 
Presentation Skills for Open Source Folks
Presentation Skills for Open Source FolksPresentation Skills for Open Source Folks
Presentation Skills for Open Source Folks
 
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
MySQL Without the SQL -- Oh My!  Longhorn PHP ConferenceMySQL Without the SQL -- Oh My!  Longhorn PHP Conference
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
Making MySQL Agile-ish
Making MySQL Agile-ishMaking MySQL Agile-ish
Making MySQL Agile-ish
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
 
MySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document StoreMySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document Store
 
Five Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverFive Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo Vancouver
 
Why Your Database Queries Stink -SeaGl.org November 11th, 2016
Why Your Database Queries Stink -SeaGl.org November 11th, 2016Why Your Database Queries Stink -SeaGl.org November 11th, 2016
Why Your Database Queries Stink -SeaGl.org November 11th, 2016
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for Newbies
 
MySQL as a Document Store
MySQL as a Document StoreMySQL as a Document Store
MySQL as a Document Store
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
 

Dernier

Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
F
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
ayvbos
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Monica Sydney
 

Dernier (20)

Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
 

Develop PHP Applications with MySQL X DevAPI

  • 1. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Session Title: Develop PHP Applications with MySQL X DevAPI • Conference: Oracle Code One • Session Type: Developer Session • Session ID: DEV5981 • Presenter: David Stokes Confidential – Oracle Internal/Restricted/Highly Restricted
  • 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Develop PHP Applications With The MySQL X DevAPI Dave Stokes MySQL Community Manager Oracle Corporation October 24, 2018 David.Stokes@Oracle.com @Stoker Confidential – Oracle Internal/Restricted/Highly Restricted
  • 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Confidential – Oracle Internal/Restricted/Highly Restricted
  • 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Who Am I Dave Stokes MySQL Community Manager @Stoker David.Stokes @ Oracle.com Slideshare.net/davidmstokes My new book -> Confidential – Oracle Internal/Restricted/Highly Restricted 4
  • 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | So What Is DEV5981 All About? Agenda Confidential – Oracle Internal/Restricted/Highly Restricted 5
  • 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Agenda 1. X Devapi – What is it? – MySQL Without the SQL – MySQL Document Store 2. Installation of PECL Extension – Where to get mysql_xdevapi and other needed software – Build the PECL Extension 3. Coding – Examples, Examples, and a few more Examples Confidential – Oracle Internal/Restricted/Highly Restricted 6
  • 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | No Code Changes Needed for Cluster Operations The code that is needed to connect to a MySQL document store looks a lot like the traditional MySQL connection code, but now applications can establish logical sessions to MySQL server instances running the X Plugin. Sessions are produced by the mysqlx factory, and the returned Sessions can encapsulate access to one or more MySQL server instances running X Plugin. Applications that use Session objects by default can be deployed on both single server setups and database clusters with no code changes. 7
  • 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Session Creation Create a Session using the mysqlx.getSession(connection) method. You pass in the connection parameters to connect to the MySQL server, such as the hostname, user and so on, very much like the code in one of the classic APIs. The connection parameters can be specified as either a URI type string, for example user:@localhost:33060, or as a data dictionary, for example {user: myuser, password: mypassword, host: example.com, port: 33060} 8
  • 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Protocol 9
  • 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | X DevAPI Part I Confidential – Oracle Internal/Restricted/Highly Restricted 10
  • 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | X Devapi -> What is it? User Guide : https://dev.mysql.com/doc/x-devapi-userguide/en/ Confidential – Oracle Internal/Restricted/Highly Restricted
  • 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | X Devapi The X DevAPI wraps powerful concepts in a simple API. ● A new high-level session concept enables you to write code that can transparently scale from single MySQL Server to a multiple server environment. ● Read operations are simple and easy to understand. ● Non-blocking, asynchronous calls follow common host language patterns. Confidential – Oracle Internal/Restricted/Highly Restricted
  • 13. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The X DevAPI introduces a new, modern and easy-to-learn way to work with your data. ● Documents are stored in Collections and have their dedicated CRUD operation set. ● Work with your existing domain objects or generate code based on structure definitions for strictly typed languages. ● Focus is put on working with data via CRUD operations. ● Modern practices and syntax styles are used to get away from traditional SQL-String-Building. Confidential – Oracle Internal/Restricted/Highly Restricted
  • 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Simple Summation You no longer have to embed ugly strings of Structured Query Language (SQL) code in your beautiful PHP Code. 14
  • 15. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The X DevAPI and Create Read, Update, and Delete (CRUD) operations. CRUD operations are available as methods, which operate on Schema objects. The available Schema objects consist of Collection objects, containing Documents, or Table objects consisting of rows and Collections containing Documents. Confidential – Oracle Internal/Restricted/Highly Restricted 15
  • 16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The following table shows the available CRUD operations for both Collection and Table objects. 16 Operation Document Relational Create Collection.add() Table.insert() Read Collection.find() Table.select() Update Collection.modify() Table.update() Delete Collection.remove() Table.delete()
  • 17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Database Object - Class Diagram 17
  • 18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Method Chaining The X DevAPI supports a number of modern practices to make working with CRUD operations easier and to fit naturally into modern development environments. This section explains how to use method chaining instead of working with SQL strings of JSON structures. 18
  • 19. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Synchronous versus Asynchronous Execution Traditionally, many MySQL drivers used a synchronous approach when executing SQL statements. This meant that operations such as opening connections and executing queries were blocked until completion, which could take a long time. To allow for parallel execution, a developer had to write a multithreaded application. Any MySQL client that supports the X Protocol can provide asynchronous execution, either using callbacks, Promises, or by explicitly waiting on a specific result at the moment in time when it is actually needed. 19
  • 20. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Working with Collections Working with collections of documents is straight forward when using the X DevAPI. The following examples show the basic usage of CRUD operations when working with documents. 20
  • 21. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 21
  • 22. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 22
  • 23. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 23
  • 24. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 24
  • 25. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | MySQL X DevAPI PECL Extension Agenda Confidential – Oracle Internal/Restricted/Highly Restricted 25
  • 26. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | An example installation procedure on Ubuntu 18.04 with PHP 7.2: // Dependencies $ apt install build-essential libprotobuf-dev libboost-dev openssl protobuf-compiler // PHP with the desired extensions; php7.2-dev is required to compile $ apt install php7.2-cli php7.2-dev php7.2-mysql php7.2-pdo php7.2-xml // Compile the extension $ pecl install mysql_xdevapi 26
  • 27. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The pecl install command does not enable PHP extensions (by default) and enabling PHP extensions can be done in several ways. Another PHP 7.2 on Ubuntu 18.04 example: // Create its own ini file $ echo "extension=mysql_xdevapi.so" > /etc/php/7.2/mods- available/mysql_xdevapi.ini // Use the 'phpenmod' command (note: it's Debian/Ubuntu specific) $ phpenmod -v 7.2 -s ALL mysql_xdevapi // A 'phpenmod' alternative is to manually symlink it // $ ln -s /etc/php/7.2/mods-available/mysql_xdevapi.ini /etc/php/7.2/cli/conf.d/20-mysql_xdevapi.ini 27
  • 28. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Check to make sure MySQL Modules loaded php -m | grep mysql mysql_xdevapi mysqli mysqlnd PDO_mysql 28
  • 29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RPM users The only way currently is to load all the needed software and build PHP from scratch. And yes, that is going to be corrected. 29
  • 30. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Examples in PHP So what does the code look like?!?! Confidential – Oracle Internal/Restricted/Highly Restricted 30
  • 31. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | X DevAPI -- Lots of similarities to mysqli and PDO 1. Connect to server a. Username, Password, Port, schema, encodings, etc. 2. Send Query 3. Get Results 4. Disconnect 31
  • 32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | QUICK Review of PHP/MySQL APIs So you have three choices now... 32
  • 33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Mysqli - replaces old, deprecated mysql interface <?php $mysqli = new mysqli("example.com", "user", "password", "database"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } if (!$mysqli->query("DROP TABLE IF EXISTS test") || !$mysqli->query("CREATE TABLE test(id INT)") || !$mysqli->query("INSERT INTO test(id) VALUES (1)")) { echo "Table creation failed: (" . $mysqli->errno . ") " . $mysqli->error; } ?> Confidential – Oracle Internal/Restricted/Highly Restricted 33
  • 34. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | PDO Confidential – Oracle Internal/Restricted/Highly Restricted 34 <?php if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { $stmt = $db->prepare('select * from foo', array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true)); } else { die("my application only works with mysql; I should use $stmt->fetchAll() instead"); } ?>
  • 35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | X Devapi Connection <?php $session = mysql_xdevapigetSession("mysqlx://user:password@host"); if ($session === NULL) { die("Connection could not be established"); } // ... use $session ?> 35
  • 36. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | So Lets Walk Through a X DevAPI Example :-) 36
  • 37. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Create a schema and a collection $schema = $session->createSchema("test"); $collection = $schema->createCollection("example"); 37
  • 38. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Create Some Data $marco = [ "name" => "Marco", "age" => 19, "job" => "Programmer" ]; $mike = [ "name" => "Mike", "age" => 39, "job" => "Manager" ]; 38
  • 39. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Store Data $schema = $session->getSchema("test"); $collection = $schema->getCollection("example"); $collection->add($marco, $mike)->execute(); var_dump($collection->find("name ='Mike'")->execute()->fetchOne()); 39
  • 40. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Fetch Data $result = $collection->find()->execute()); foreach ($result as $doc) { echo "${doc["name"]} is a ${doc["job"]}.n"; } 40
  • 41. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Yet More Examples! Subtitle Confidential – Oracle Internal/Restricted/Highly Restricted 41
  • 42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 42 #!/usr/bin/php <?PHP // Connection parameters $user = 'root'; $passwd = 'S3cret#'; $host = 'localhost'; $port = '33060'; $connection_uri = 'mysqlx://'.$user.':'.$passwd.'@'.$host.':'.$port; echo $connection_uri . "n"; // Connect as a Node Session $nodeSession = mysql_xdevapigetNodeSession($connection_uri); // "USE world_x" schema $schema = $nodeSession->getSchema("world_x"); // Specify collection to use $collection = $schema->getCollection("countryinfo"); // SELECT * FROM world_x WHERE _id = "USA" $result = $collection->find('_id = "USA"')->execute(); // Fetch/Display data $data = $result->fetchAll(); var_dump($data); ?>
  • 43. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 43 #!/usr/bin/php <?PHP // Connection parameters $user = 'root'; $passwd = 'S3cret#'; $host = 'localhost'; $port = '33060'; $connection_uri = 'mysqlx://'.$user.':'.$passwd.'@'.$host.':'.$port; echo $connection_uri . "n"; // Connect as a Node Session $nodeSession = mysql_xdevapigetNodeSession($connection_uri); // "USE world_x" schema $schema = $nodeSession->getSchema("world_x"); // Specify collection to use $collection = $schema->getCollection("countryinfo"); // SELECT * FROM world_x WHERE _id = "USA" $result = $collection->find('_id = "USA"')->execute(); // Fetch/Display data $data = $result->fetchAll(); var_dump($data); ?>
  • 44. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 44 #!/usr/bin/php <?PHP // Connection parameters $user = 'root'; $passwd = 'S3cret#'; $host = 'localhost'; $port = '33060'; $connection_uri = 'mysqlx://'.$user.':'.$passwd.'@'.$host.':'.$port; echo $connection_uri . "n"; // Connect as a Node Session $nodeSession = mysql_xdevapigetNodeSession($connection_uri); // "USE world_x" schema $schema = $nodeSession->getSchema("world_x"); // Specify collection to use $collection = $schema->getCollection("countryinfo"); // SELECT * FROM world_x WHERE _id = "USA" $result = $collection->find('_id = "USA"')->execute(); // Fetch/Display data $data = $result->fetchAll(); var_dump($data); ?>
  • 45. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 45 #!/usr/bin/php <?PHP // Connection parameters $user = 'root'; $passwd = 'S3cret#'; $host = 'localhost'; $port = '33060'; $connection_uri = 'mysqlx://'.$user.':'.$passwd.'@'.$host.':'.$port; echo $connection_uri . "n"; // Connect as a Node Session $nodeSession = mysql_xdevapigetNodeSession($connection_uri); // "USE world_x" schema $schema = $nodeSession->getSchema("world_x"); // Specify collection to use $collection = $schema->getCollection("countryinfo"); // SELECT * FROM world_x WHERE _id = "USA" $result = $collection->find('_id = "USA"')->execute(); // Fetch/Display data $data = $result->fetchAll(); var_dump($data); ?>
  • 46. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 46 <?php $uri = "mysqlx://root:XXX@localhost:33060/?ssl-mode=disabled"; $nodeSession = mysql_xdevapigetSession( $uri ); $schema = $nodeSession->createSchema( "testx" ); $coll = $schema->createCollection( "store" ); $result = $coll->add( '{ "product" : "iPhone X", "price":1000, "stock" : 2 }' )->execute(); print 'The generated ID for the document is: ' . $result- >getDocumentId() . PHP_EOL; ?>
  • 47. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 47 $uri = "mysqlx://root:XXX@localhost:33060?ssl-mode=disabled"; $nodeSession = mysql_xdevapigetSession( $uri ); $schema = $nodeSession->createSchema( "testx" ); $coll = $schema->createCollection( "store" ); $result = $coll->add( '{ "product" : "iPhone X", "price":1000, "stock" : 2 }' '{ "product" : "Nokia Y", "price":900, "stock" : 3, "description": "A good mobile phone" }' )->execute(); $item_count = $result->getAffectedItemsCount(); print($item_count." documents has been added to the collection, printing ID's"); $ids = $result->getGeneratedIds(); for( $i = 0 ; $i < $item_count ; $i++ ) { print("The document ID number ".$i." is ".$ids[$i].PHP_EOL); }
  • 48. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 48 //Add some documents, note that I'm providing the IDs myself $res = $coll->add( ["_id" => "1", "name" => "Carlotta", "age" => 34, "job" => "Dentista"], ["_id" => "2", "name" => "Antonello", "age" => 45, "job" => "Tassinaro"], ["_id" => "3", "name" => "Mariangela", "age" => 32, "job" => "Attrice"], ["_id" => "4", "name" => "Antonio", "age" => 42, "job" => "Urologo"] )->execute(); //Remove the document with ID 4 $coll->removeOne("4"); //Find all the entries for which the 'age' field is greater than 30 $res = $coll->find("age > 30")->execute(); //Fetch the entries $data = $res->fetchAll(); //Print the results for( $i = 0 ; $i < count( $data ) ; $i++ ) { print($data[$i]["name"]." have more than 30 years!"); }
  • 49. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 49 //Fill the collection with some documents $coll->add('{"name": "Sakila", "age": 15, "job": "Programmer"}', '{"name": "Sakila", "age": 17, "job": "Singer"}', '{"name": "Sakila", "age": 18, "job": "Student"}', '{"name": "Arnold", "age": 24, "job": "Plumber"}', '{"name": "Robert", "age": 39, "job": "Manager"}')->execute(); //This modify operation will change the 'job' to 'Unemployed' for all //the three Sakila in the collection $coll->modify("name like 'Sakila'")->set("job", "Unemployed")->execute(); //Add a second job to Arnold, the field 'job' will now on be an array //of two elements: 'Plumber' and 'Nursey' $coll->modify("name like 'Arnold'")->arrayAppend('job','Nursey')->execute();
  • 50. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | What About Relational Tables?? Yet More Examples! 50
  • 51. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 51 <?php $session = mysql_xdevapigetSession("mysqlx://root:secret@localhost"); $session->sql("DROP DATABASE IF EXISTS addressbook")->execute(); $session->sql("CREATE DATABASE addressbook")->execute(); $session->sql("CREATE TABLE addressbook.names(name text, age int)")- >execute(); $session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute(); $schema = $session->getSchema("addressbook"); $table = $schema->getTable("names"); $row = $table->select('name', 'age')->execute()->fetchAll(); print_r($row);
  • 52. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 52 #!/bin/php <?php $session = mysql_xdevapigetSession("mysqlx://root:hidave@localhost:33060"); if ($session === NULL) { die("Connection could not be established"); } $schema = $session->getSchema("world"); $table = $schema->getTable("city"); $row = $table->select('Name','District') ->where('District like :district') ->bind(['district' => 'Texas']) ->execute()->fetchAll(); print_r($row);
  • 53. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Q/A ? Confidential – Oracle Internal/Restricted/Highly Restricted 53
  • 54. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 54 Slides posted to https://slideshare.net/davidmstokes @stoker or David.Stokes @ Oracle.com