Native implementation of new MySQL communication protocol (protocol x). Library does not depended on any existing MySQL database extension or on any other additional C extension.
This library is experimental and work in progress! Library at this moment does not perform input escaping or using prepared statements (both is very much work in progress)!
Prefered way to install library is with composer:
composer require kambo/protocolx
// Connection parameters
$connectionParameters = [
'host' => 'databasehost',
'port' => 33060,
'dbUser' => 'username',
'dbPassword' => 'password'
];
// Create instance of Mysqlx working throught new MySQL protocolx
$mysqlx = new Mysqlx(new Protocolx());
// Creates a NodeSession instance representing a connection to one MySQL server.
$serverSession = $mysqlx->getNodeSession($sessionParameters);
// Get a specified database schema (database).
$testDatabaseSchema = $serverSession->getSchema('test_database');
// Gets all collections in the schema (database).
$testDatabaseSchema->getCollections();
// Gets particular collection from the schema (database).
$testingCollection = $testDatabaseSchema->getCollection('testing_collection');
// Create new collection named "new_collection"
$newCollection = $testDatabaseSchema->createCollection('new_collection');
// Drop existing collection from schema
$testDatabaseSchema->dropCollection('new_collection');
// Modified existing document with id 1010
$modifyDocument = $testingCollection->modify(['_id'=>1010]);
$modifyDocument->setItem('foo', 'bar');
$operationResult = $modifyDocument->execute(); // Execute operation
// Add new document to the collection
$addOperation = $testingCollection->add([['new'=> ['foo'=>'bar']]]);
$addOperation->execute(); // Execute operation
// Remove document with id 1010 from collection
$removeOperation = $collection->remove(['_id'=>1010]);
$removeOperation->execute(); // Execute operation
// Returns all documents in collection
$findOperation = $testingCollection->find(null);
$collectionDocuments = $findOperation->execute()->fetchAll(); // Execute operation
// Returns only document with specific id
$findOperation = $testingCollection->find(['_id' => '1003']);
$collectionDocuments = $findOperation->execute()->fetchAll(); // Execute operation
// Library at this moment support just Mongo query language, thus:
// ['answer' => ['$gt'=>44]] will return all documents which have
// in answer field value bigger then 44.
$findOperation = $testingCollection->find(['answer' => ['$gt'=>44]]);
$collectionDocuments = $findOperation->execute()->fetchAll(); // Execute operation
The MIT License (MIT), https://opensource.org/licenses/MIT