mysql

(mysql).MySQLClient

MySQLClient is a client for MySQL database. Internally client uses go-sql-driver/mysql driver.

Kind: inner class of mysql

mySQLClient.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.

Kind: instance method of MySQLClient
Returns: bool - - The result of the connection attempt.
Throws:

  • error - The error encountered during connection attempt.
ParamTypeDescription
hoststringThe host of the MySQL database.
portintThe port of the MySQL database.
usernamestringThe username to connect to the MySQL database.
passwordstringThe password to connect to the MySQL database.

Example

let m = require('nuclei/mysql');
let c = m.MySQLClient();
let result = c.Connect('localhost', 3306, 'root', 'password');

mySQLClient.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.

Kind: instance method of MySQLClient
Returns: bool - - The result of the connection attempt.
Throws:

  • error - The error encountered during connection attempt.
ParamTypeDescription
hoststringThe host of the MySQL database.
portintThe port of the MySQL database.
usernamestringThe username to connect to the MySQL database.
passwordstringThe password to connect to the MySQL database.
dbNamestringThe name of the database to connect to.

Example

let m = require('nuclei/mysql');
let c = m.MySQLClient();
let result = c.ConnectWithDB('localhost', 3306, 'root', 'password', 'mydb');

mySQLClient.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.

Kind: instance method of MySQLClient
Returns: string - - The result of the query execution.
Throws:

  • error - The error encountered during query execution.
ParamTypeDescription
hoststringThe host of the MySQL database.
portintThe port of the MySQL database.
usernamestringThe username to connect to the MySQL database.
passwordstringThe password to connect to the MySQL database.
dbNamestringThe name of the database to connect to.
querystringThe query to execute on the database.

Example

let m = require('nuclei/mysql');
let c = m.MySQLClient();
let result = c.ExecuteQuery('localhost', 3306, 'root', 'password', 'mydb', 'SELECT * FROM users');

mySQLClient.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.

Kind: instance method of MySQLClient
Returns: bool - - The result of the check.
Throws:

  • error - The error encountered during the check.
ParamTypeDescription
hoststringThe host to check.
portintThe port to check.

Example

let m = require('nuclei/mysql');
let c = m.MySQLClient();
let result = c.IsMySQL('localhost', 3306);