Methods
Connect(host, port, username, password) → {bool}
Connect connects to MySQL database using given credentials. If connection is successful, it returns true. If connection is unsuccessful, it returns false and error. The connection is closed after the function returns.
Parameters:
Name | Type | Description |
---|---|---|
host | string | The host of the MySQL database. |
port | int | The port of the MySQL database. |
username | string | The username to connect to the MySQL database. |
password | string | The password to connect to the MySQL database. |
- Source
Throws:
- - The error encountered during connection attempt.
- Type
- error
Returns:
- The result of the connection attempt.
- Type:
- bool
Example
let m = require('nuclei/mysql');
let c = m.MySQLClient();
let result = c.Connect('localhost', 3306, 'root', 'password');
ConnectWithDB(host, port, username, password, dbName) → {bool}
ConnectWithDB connects to MySQL database using given credentials and database name. If connection is successful, it returns true. If connection is unsuccessful, it returns false and error. The connection is closed after the function returns.
Parameters:
Name | Type | Description |
---|---|---|
host | string | The host of the MySQL database. |
port | int | The port of the MySQL database. |
username | string | The username to connect to the MySQL database. |
password | string | The password to connect to the MySQL database. |
dbName | string | The name of the database to connect to. |
- Source
Throws:
- - The error encountered during connection attempt.
- Type
- error
Returns:
- The result of the connection attempt.
- Type:
- bool
Example
let m = require('nuclei/mysql');
let c = m.MySQLClient();
let result = c.ConnectWithDB('localhost', 3306, 'root', 'password', 'mydb');
ExecuteQuery(host, port, username, password, dbName, query) → {string}
ExecuteQuery connects to Mysql database using given credentials and database name and executes a query on the db.
Parameters:
Name | Type | Description |
---|---|---|
host | string | The host of the MySQL database. |
port | int | The port of the MySQL database. |
username | string | The username to connect to the MySQL database. |
password | string | The password to connect to the MySQL database. |
dbName | string | The name of the database to connect to. |
query | string | The query to execute on the database. |
- Source
Throws:
- - The error encountered during query execution.
- Type
- error
Returns:
- The result of the query execution.
- Type:
- string
Example
let m = require('nuclei/mysql');
let c = m.MySQLClient();
let result = c.ExecuteQuery('localhost', 3306, 'root', 'password', 'mydb', 'SELECT * FROM users');
IsMySQL(host, port) → {bool}
IsMySQL checks if the given host is running MySQL database. If the host is running MySQL database, it returns true. If the host is not running MySQL database, it returns false.
Parameters:
Name | Type | Description |
---|---|---|
host | string | The host to check. |
port | int | The port to check. |
- Source
Throws:
- - The error encountered during the check.
- Type
- error
Returns:
- The result of the check.
- Type:
- bool
Example
let m = require('nuclei/mysql');
let c = m.MySQLClient();
let result = c.IsMySQL('localhost', 3306);