MySQL Module
From Documentation
MySQL Module for Eggdrop
- Coded by BarkerJr
- Beta tested by David "DrN" Proper
This module is designed to be an alternative to installing Tcl modules. This is made especially for Eggdrops.
Contents |
Installation
MySQL Server
Skip to the next section if you already have MySQL server and libraries installed.
- Download the following three modules from dev.mysql.com:
- Server
- Client
- Headers and Libraries
- Become root
- Run the following commands:
- rpm -i <server file>
- rpm -i <headers file>
- rpm -i <client file>
Eggdrop Module
- Obtain this package.
- Place it in ~/eggdrop1.6.x/src/mod/
- Decompress it: tar jxvf mysqlx.x.tar.bz2
- Go back to your ~/eggdrop1.6.x directory
- ./configure (if needed)
- make config
- make
- make install
- Edit you bot's *.conf file and add the line: loadmodule mysql
- Rehash your bot
Tcl Commands
- mysql_connect <database> <hostname> [user] [password] [socket|port]
- Initializes the connection to the database. If hostname is `localhost', the connection will be piped into a socket instead of using a tcp port. Socket is the path to the unix socket, such as /tmp/mysql.sock.
- mysql_close
- Closed the current database connection, freeing its memory.
- mysql_query <query>
- Executes a query and returns its results in a nested list. A semi-colon is automatically appended to the end of the statement.
- mysql_escape [bytes] <string>
- Makes a string safe to be used in MySQL. Adds backslashes before single quotes, doubles backslashes, and so on. Only specify the bytes argument if you are handling binary data. Using it incorrectly will crash your bot, or worse.
- mysql_errno
- Returns the error code that was last encountered. A list of error codes is available at: http://www.mysql.com/doc/en/Error-returns.html
- mysql_ping
- Checks whether the connection to the server is working. If it has gone down, an automatic reconnection is attempted.
- mysql_connectioninfo
- If connected, returns a list of database name, hostname, user, and port/sock.
- mysql_insert_id
- Returns the ID from the last insertion.
- mysql_connected
- Return whether the module thinks the database is linked (true) or not (false).
- This is a client-side command, so it does not verify that the underlying (TCP) connection is still alive
- mysql_affected_rows
- Returns the number of rows that were changed by the last query.
Scripts for MySQL.mod
Please add links to your scripts based on this module.
- MySeen
- This is a fully-functional sample script for the module, by BarkerJr
To Do List
Feel free to add to this list or program some of the items.
- Add mysql_pconnect as an alias for mysql_connect, so as to ease conversion from PHP.
- Remove the "mysql/" prefix in mysql_mod.h, since the mysql_config should point directly to the file, not the directory above.
- Add inter-module C-functions so that other modules can call this one.
- Move the module documentation into this wiki, instead of inside the tarball.
- Support multiple database connections.
- Allow null database name (queries will need to be prefixed with dbname)
