back to mysql 

mysql.Database

generated from ../src/mod_mysql/db.cpp

The class is used for accessing a MySQL database. More information about the MySQL database server can be found at MySQL.

Constants

Multi Options

Name Description
OPTION_MULTI_STATEMENTS_ON Enable multiple-statement support
OPTION_MULTI_STATEMENTS_OFF Disable multiple-statement support.

Refresh

Name Description
REFRESH_GRANT Refresh the grant tables, like FLUSH PRIVILEGES.
REFRESH_LOG Flush the logs, like FLUSH LOGS.
REFRESH_TABLES Flush the table cache, like FLUSH TABLES
REFRESH_HOSTS Flush the host cache, like FLUSH HOSTS.
REFRESH_STATUS Reset status variables, like FLUSH STATUS.
REFRESH_THREADS Flush the thread cache.
REFRESH_SLAVE On a slave replication server, reset the master server information and restart the slave, like RESET SLAVE.
REFRESH_MASTER On a master replication server, remove the binary log files listed in the binary log index and truncate the index file, like RESET MASTER

Use these constants in refresh

options

Name Description
INIT_COMMAND Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting.
OPT_COMPRESS Use the compressed client/server protocol.
OPT_CONNECT_TIMEOUT Connect timeout in seconds.
OPT_GUESS_CONNECTION For an application linked against libmysqld, this allows the library to guess whether to use the embedded server or a remote server. “Guess” means that if the hostname is set and is not localhost, it uses a remote server. This behavior is the default. MYSQL_OPT_USE_EMBEDDED_CONNECTION and MYSQL_OPT_USE_REMOTE_CONNECTION can be used to override it. This option is ignored for applications linked against libmysqlclient.
OPT_LOCAL_INFILE If no pointer is given or if pointer points to an unsigned int != 0 the command LOAD LOCAL INFILE is enabled.
OPT_NAMED_PIPE Use named pipes to connect to a MySQL server on NT.
OPT_PROTOCOL Type of protocol to use. Should be one of the enum values of mysql_protocol_type defined in mysql.h.
OPT_READ_TIMEOUT Timeout for reads from server (works only for TCP/IP connections, and only for Windows prior to MySQL 5.0.25). You can this option so that a lost connection can be detected earlier than the TCP/IP Close_Wait_Timeout value of 10 minutes.
OPT_RECONNECT Enable or disable automatic reconnection to the server if the connection is found to have been lost. Reconnect has been off by default since MySQL 5.0.3; this option is new in 5.0.13 and provides a way to set reconnection behavior explicitly.
OPT_SSL_VERIFY_SERVER_CERT Enable or disable verification of the server's Common Name value in its certificate against the hostname used when connecting to the server. The connection is rejected if there is a mismatch. This feature can be used to prevent man-in-the-middle attacks. Verification is disabled by default. Added in MySQL 5.0.23.
OPT_USE_EMBEDDED_CONNECTION For an application linked against libmysqld, this forces the use of the embedded server for the connection. This option is ignored for applications linked against libmysqlclient.
OPT_USE_REMOTE_CONNECTION For an application linked against libmysqld, this forces the use of a remote server for the connection. This option is ignored for applications linked against libmysqlclient.
OPT_USE_RESULT This option is unused.
OPT_WRITE_TIMEOUT Timeout for writes to server (works currently only on Windows on TCP/IP connections).
READ_DEFAULT_FILE Read options from the named option file instead of from my.cnf.
READ_DEFAULT_GROUP Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE.
REPORT_DATA_TRUNCATION Enable or disable reporting of data truncation errors for prepared statements via MYSQL_BIND.error. (Default: enabled) Added in 5.0.3.
SECURE_AUTH Whether to connect to a server that does not support the password hashing used in MySQL 4.1.1 and later.
SET_CHARSET_DIR The pathname to the directory that contains character set definition files.
SET_CHARSET_NAME The name of the character set to use as the default character set.
SHARED_MEMORY_BASE_NAME Named of shared-memory object for communication to server. Should be same as the option --shared-memory-base-name used for the mysqld server you want to connect to.

Use these constants in options

Class Properties

Name Type Description
clientInfo read only String Returns a string that represents the client library version.
clientVersion read only Integer Returns an integer that represents the client library version. The value has the format XYYZZ where X is the major version, YY is the release level, and ZZ is the version number within the release level. For example, a value of 40102 represents a client library version of 4.1.2.

Constructor

Database

Database()
 

Constructs a new Database object

Properties

Name Type Description
affectedRows read only Integer Returns the number of rows changed by the last UPDATE, deleted by the last DELETE or inserted by the last INSERT statement. May be called immediately after query for UPDATE, DELETE, or INSERT statements. For SELECT statements, affectedRows works like numRows.
characterSet read only String The character set used by wxJavaScript
errno read only Integer Returns the error number for the most recently invoked Database function.
error read only String A string containing the error message for the most recently invoked Database function that failed. If a function didn't fail, the return value may be the previous error or an empty string to indicate no error.
fieldCount read only Integer Returns the number of columns for the most recent query on the connection.
hostInfo read only String Returns a string describing the type of connection in use, including the server hostname.
info read only String Retrieves a string providing information about the most recently executed query.
insertId read only Integer Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement. Use this property after you have performed an INSERT statement into a table that contains an AUTO_INCREMENT field. Note that insertId returns 0 if the previous statement does not use an AUTO_INCREMENT value. If you need to save the value for later, be sure to store the value of insertId in a variable.
moreResults read only Boolean This property is used when you execute multiple statements specified as a single statement string, or when you execute CALL statements, which can return multiple result sets.
moreResults returns true if more results exist from the currently executed statement, in which case the application must call next.
protoInfo read only Integer Returns the protocol version used by current connection.
serverInfo read only String Returns the version number of the server as a String.
serverVersion read only Integer Returns the version number of the server as an integer.
sqlState read only String Returns a string containing the SQLSTATE error code for the most recently executed SQL statement.
stat read only String Returns a string containing information similar to that provided by the mysqladmin status command. This includes uptime in seconds and the number of running threads, questions, reloads, and open tables.
warningCount read only Integer Returns the number of warnings generated during execution of the previous SQL statement.

Methods

autocommit

autocommit(Mode) : Boolean
 
Name Type Default Description
Mode Boolean

Sets autocommit mode on if mode is true, off if mode is false.

changeUser

changeUser(User, 
           Passwd = null, 
           Db = null) : Boolean
 
Name Type Default Description
User String Name of the user
Passwd String null Password of the user
Db String null Name of the database

Changes the user and causes the database specified by Db to become the default (current) database. In subsequent queries, this database is the default for table references that do not include an explicit database specifier.

changeUser fails if the connected user cannot be authenticated or doesn't have permission to use the database. In this case, the user and database are not changed.

The db parameter may be set to null if you don't want to have a default database.

This command always performs a ROLLBACK of any active transactions, closes all temporary tables, unlocks all locked tables and resets the state as if one had done a new connect. This happens even if the user didn't change.

commit

commit() : Boolean
 

Commits the current transaction.

connect

connect(Host = "", 
        User = "", 
        Passwd = "", 
        Db = "", 
        Port = 0, 
        UnixSocket = "") : Boolean
 
Name Type Default Description
Host String Name of the host
User String Name of the user
Passwd String Password of the user
Db String Name of the database
Port Integer 0 Port of the database
UnixSocket String Specifies the socket or named pipe that should be used

Connects to a Database database

listDbs

listDbs(Wild = "") : Result
 
Name Type Default Description
Wild String Simple regular expression for matching a name

Returns a result set consisting of database names on the server that match the simple regular expression specified by the Wild parameter. Wild may contain the wildcard characters "%" or "_" or may be an empty string to match all databases

listFields

listFields(Table, 
           Wild = "") : Result
 
Name Type Default Description
Table String Name of the table
Wild String Simple regular expression for matching a name

Returns a result set consisting of field names in the given table that match the simple regular expression specified by the wild parameter. Wild may contain the wildcard characters "%" or "_", or may be an empty string to match all fields

listProcesses

listProcesses() : Result
 

Returns a result set describing the current server threads. This is the same kind of information as that reported by mysqladmin processlist or a SHOW PROCESSLIST query.

listTables

listTables(Wild = "") : Result
 
Name Type Default Description
Wild String Simple regular expression for matching a name

Returns a result set consisting of field names in the given table that match the simple regular expression specified by the wild parameter. Wild may contain the wildcard characters "%" or "_", or may be an empty string to match all fields

options

options(Option, 
        Value) : Integer
 
Name Type Default Description
Option Integer
Value Any

Can be used to set extra connect options and affect behavior for a connection. This function may be called multiple times to set several options. See options

ping

ping() : Integer
 

Checks whether the connection to the server is working. If the connection has gone down, an automatic reconnection is attempted.

This function can be used by clients that remain idle for a long while, to check whether the server has closed the connection and reconnect if necessary.

Return Values: Zero if the connection to the server is alive. Non-zero if an error occurred. A non-zero return does not indicate whether the MySQL server itself is down; the connection might be broken for other reasons such as network problems.

prepare

prepare(SQL) : Statement
 
Name Type Default Description
SQL String An SQL statement

Prepares an SQL statement. The application can include one or more parameter markers in the SQL statement by embedding question mark ("?") characters into the SQL string at the appropriate positions.

The markers are legal only in certain places in SQL statements. For example, they are allowed in the VALUES() list of an INSERT statement (to specify column values for a row), or in a comparison with a column in a WHERE clause to specify a comparison value. However, they are not allowed for identifiers (such as table or column names), or to specify both operands of a binary operator such as the = equal sign. The latter restriction is necessary because it would be impossible to determine the parameter type. In general, parameters are legal only in Data Manipulation Language (DML) statements, and not in Data Definition Language (DDL) statements.

The parameter markers must be bound to application variables using bind before executing the statement.
On failure null is returned.

query

query() : Result
 

Executes the SQL statement. When a statement returns rows, Result object is returned. Otherwise null is returned. null is also returned on failure. You can use fieldCount to get the number of returned fields in a row.

refresh

refresh(Options) : Integer
 
Name Type Default Description
Options Integer

This functions flushes tables or caches, or resets replication server information. The connected user must have the RELOAD privilege.

The options argument is a bit mask composed from any combination of the following values. Multiple values can be OR'ed together to perform multiple operations with a single call.

Returns zero for success, non-zero if an error occurred.

rollback

rollback() : Integer
 

Rolls back the current transaction.

selectDb

selectDb(Database) : Integer
 
Name Type Default Description
Database String Name of the database

Causes the database specified by Database to become the default (current) database on the connection specified by mysql. In subsequent queries, this database is the default for table references that do not include an explicit database specifier.

selectDb fails unless the connected user can be authenticated as having permission to use the database.

setServerOption

setServerOption(Option) : Integer
 
Name Type Default Description
Option Integer

Enables or disables an option for the connection. option can have one of the following values: mysql.Database.OPTION_MULTI_STATEMENTS_ON or mysql.Database.OPTION_MULTI_STATEMENTS_OFF

sslSet

sslSet(Key, 
       Cert, 
       Ca, 
       CaPath, 
       Cipher) : Integer
 
Name Type Default Description
Key String Key is the pathname to the key file
Cert String Cert is the pathname to the certificate file.
Ca String Ca is the pathname to the certificate authority file.
CaPath String CaPath is the pathname to a directory that contains trusted SSL CA certificates in pem format.
Cipher String Cipher is a list of allowable ciphers to use for SSL encryption.




Design downloaded from Zeroweb.org: Free website templates, layouts, and tools.