[ next ] [ language reference ] [ table of contents ]
Interact with a MySQL database server by connecting and optionally executing queries.
On the initial connection, this command will attempt to execute the query “SHOW STATUS” to gain the value of all status variables maintained by MySQL. These variables will be added to the global namespace as MYSQL_STATUS_X where “X” is the name of the variable. For instance, after executing this command:
mysql connect "guest" "love" "mysql"
if $MYSQL_STATUS_ABORTED_CLIENTS > 10 then error "aborted clients"
After connecting to a MySQL server, you can execute any number of queries. The scripting engine uses a single cursor for a connection to the server, so each query will over write the results from the last. This sample code illustrates how to execute a query and retrieve the results:
mysql exec 'select user_id, email, status from users'
for REC = 1 to $MYSQL_ROW_COUNT begin
mysql cursor next
if $MYSQL_COLUMN_status = "A" then begin
info $MYSQL_COLUMN_0 + ", " + $MYSQL_COLUMN_email + ", Active"
else
info $MYSQL_COLUMN_0 + ", " + $MYSQL_COLUMN_email + ", Not Active"
end
end
req | name | type | description |
---|---|---|---|
Y | operation | keyword | One of: - connect: Connects to the MySQL server, logs in and selects the given database. - exec: Executes the query with the MySQL connection opened by a call to connect . - cursor: Performs cursor operations based on the previously executed query. - close: Closes the connection to MySQL. |
N | user | expression | Login ID used to connect to the server |
N | password | expression | Password used to authenticate the connection to the server |
N | database | expression | Name of database to use after connecting |
N | query | expression | The query to execute |
N | next | expression | Moves the cursor to the next record |
mysql connect “guest” “love” “mysql”
Connect to the given MySQL server with the user ID “guest”, a password of “love”. The database “mysql” will be used.
mysql exec “select * from users”
Executes the query using the existing connection to the MySQL server.
mysql cursor next
Move the resultset cursor from the current record (or the beginning of the resultset) to the next record.
mysql close
Close the current connection to the MySQL server. Also closes the outstanding cursor if necessary.
Alertra Script Language: Language Reference