Skip to content

Commit 73fd221

Browse files
committed
ok
1 parent 9ae5def commit 73fd221

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ contains functions for simple operations with ClickHouse.
4343
* **getTableFields**($table, ...) - returns [field_name=>field_type] array
4444
* **getTableInfo**($table [, $extended]) - returns array with info about table
4545
* **getTablesList**([$db] [,$pattern]) - returns tables list by SHOW TABLES request
46+
* **createDatabase**($db) - create new database with specified name
47+
* **dropDatabase**($db) - drop specified database and remove all tables inside
4648
* **getDatabasesList**() - returns array contained names of existing Databases
4749
* **setCurrentDatabase**($db [, $sess]) - set current database by 'USE db' request
4850
* **getCurrentDatabase**([$sess]) - return results of 'SELECT currentDatabase()'

src/ClickHouseFunctions.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*
1717
* - >getTablesList([$db] [,$pattern]) - returns tables list by SHOW TABLES request
1818
*
19+
* - >createDatabase($db) - create new database with specified name
20+
* - >dropDatabase($db) - drop specified database and remove all tables inside
1921
* - >getDatabasesList() - returns array contained names of existing Databases
2022
* - >setCurrentDatabase($db [, $sess]) - set current database by 'USE db' request
2123
* - >getCurrentDatabase([$sess]) - return results of 'SELECT currentDatabase()'
@@ -436,16 +438,29 @@ public function setCurrentDatabase($db, $sess = null)
436438
}
437439
}
438440

439-
441+
/**
442+
* Drop database and remove all tables inside it.
443+
*
444+
* @param type $db_name database name for drop (delete, remove)
445+
* @param boolean $if_exists Add condition "IF EXISTS"
446+
* @return false|string false if ok, or string with error description
447+
*/
440448
public function dropDatabase($db_name, $if_exists = false)
441449
{
442-
$sql = "DROP DATABASE " . ($if_exists ? 'IF EXISTS ':'');
450+
$sql = "DROP DATABASE " . ($if_exists ? 'IF EXISTS ' : '');
443451
return $this->queryFalse($sql . $db_name);
444452
}
445453

454+
/**
455+
* Create new database
456+
*
457+
* @param string $db_name database name for create
458+
* @param boolean $if_not_exists Add condition "IF NOT EXISTS"
459+
* @return false|string false if ok, or string with error description
460+
*/
446461
public function createDatabase($db_name, $if_not_exists = false)
447462
{
448-
$sql = "CREATE DATABASE " . ($if_not_exists ? 'IF NOT EXISTS ':'');
463+
$sql = "CREATE DATABASE " . ($if_not_exists ? 'IF NOT EXISTS ' : '');
449464
return $this->queryFalse($sql . $db_name);
450465
}
451466

src/ClickHouseQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function queryTrue($sql, $post_data = [], $sess = null)
157157
* @param string $sql SQL-request
158158
* @param string|array|null $post_data any POST-data or null for GET-request
159159
* @param string|null $sess session_id
160-
* @return boolean|string False if no errors | string if error with describe
160+
* @return string|false False if no errors | string if error with describe
161161
*/
162162
public function queryFalse($sql, $post_data = [], $sess = null)
163163
{

0 commit comments

Comments
 (0)