thrownewInvalidArgumentException("The MySQLDatabase driver is intended to be used when your main database product is MySQL. We recommend whether you pick the same engine for collections and other db use, whether you use a key/store storage solution for collections, like MongoDB.");
thrownewException("Configuration parameter missing: \$Config['DocumentStorage']['Table']. Expected value for this parameter is the table to store the collections documents.");
}
$this->table=$Config['DocumentStorage']['Table'];
}else{
$this->table=$table;
}
$this->id=$id;
$this->initializeCollectionsTable();
}
///
/// Helper to create schema if required
///
/**
* Initializes collections table
*/
protectedfunctioninitializeCollectionsTable(){
if(defined('COLLECTIONS_MYSQL_DATABASE_READY')
&&COLLECTIONS_MYSQL_DATABASE_READY){
return;
}
self::$client->query("
CREATE TABLE if not exists $this->table (
collection_id VARCHAR(255),
document_id VARCHAR(255),
document_value BLOB,
PRIMARY KEY (collection_id, document_id)
);",
);
define('COLLECTIONS_MYSQL_DATABASE_READY',true);
}
///
/// SqlCollection implementation
///
/**
* Executes a SQL query
*
* @param string $sql The SQL query
*
* @return mixed If the query doesn't return any result, null. If the query
* return a row with one field, the scalar value. Otherwise, an
* associative array, the fields as keys, the row as values.