Skip to content

Commit

Permalink
🔀 Merge branch 'main' of https://github.com/MariaDB/catalogs-php
Browse files Browse the repository at this point in the history
  • Loading branch information
synio-wesley committed Mar 17, 2024
2 parents 998a01c + 28538c7 commit 82db661
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $catalog->create('catalog_name');
## Return a list of all existing catalogs

```php
$catalogs = $catalog->show();
$catalogs = $catalog->list();
/*
Returns an array of catalogs on MariaDB:
Array
Expand Down
8 changes: 5 additions & 3 deletions src/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(
protected string $dbUser='root',
protected string $dbPass='',
protected ?array $dbOptions=null,
protected ?\PDO $pdo = null
protected ?\PDO $pdo=null
) {
// Connect.
try {
Expand Down Expand Up @@ -79,6 +79,7 @@ public function __construct(

}


/**
* Create a new catalog
*
Expand All @@ -89,7 +90,7 @@ public function __construct(
public function create(string $catName): int
{
// Check if the Catalog name is valid.
if (in_array($catName, array_keys($this->show())) === true) {
if (in_array($catName, array_keys($this->list())) === true) {
throw new Exception('Catalog name already exists.');
}

Expand Down Expand Up @@ -160,7 +161,7 @@ public function getPort(string $catName): int
*
* @return int[] Named array with cat name and port.
*/
public function show(): array
public function list(): array
{
$catalogs = [];
$results = $this->connection->query('SHOW CATALOGS');
Expand Down Expand Up @@ -261,6 +262,7 @@ public function createAdminUserForCatalog(
$this->connection->prepare(
"CREATE USER ?@? IDENTIFIED BY ?;"
)->execute([$userName, $authHost, $password]);

$this->connection->prepare(
"GRANT ALL PRIVILEGES ON `%`.* TO ?@? IDENTIFIED BY ? WITH GRANT OPTION;"
)->execute([$userName, $authHost, $password]);
Expand Down

0 comments on commit 82db661

Please sign in to comment.