As the following will show, you don't have to use an external DLL to grab data from a MySQL database. Granted, the example below is very simplified from what you might want to do, but it
will show that it is entirely possible, and even very feasible, to work with MySQL directly from within mIRC. I have done it from the mIRC command line.
Assuming you have MySQL installed properly (if you don't, get
MySQL and
OLEDB provider), I will show all the steps required to make this all work.
[color:000066]1. CREATING THE DATABASE/TABLE AND ADDING DATA TO IT[/color]/run cmdE:\mIRC\> [color:#840017]C:C:\>
cd mysql\binC:\mysql\bin\>
mysqlWelcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 28 to server version: 4.0.23-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
CREATE DATABASE myDatabaseName;Query OK, 1 row affected (0.01 sec)
mysql>
USE myDatabaseName;Database changed
mysql>
GRANT ALL ON myDatabaseName.*- - - >
TO myUsername[/b]@[/b]localhost - - - >
IDENTIFIED BY 'myPassword';Query OK, 0 rows affected (0.15 sec)
mysql>
CREATE TABLE Nicks (- - - >
NickID int unsigned not null auto_increment primary key,- - - >
Nickname varchar(30) not null default 'NoNick',- - - >
FirstName varchar(50) default ' ',- - - >
LastName varchar(50) default ' ',- - - >
Gender varchar(1) default 'M'- - - >
);Query OK, 0 rows affected (0.09 sec)
mysql>
INSERT INTO Nicks (Nickname, FirstName, LastName, Gender)- - - >
VALUES ('JDoe', 'John', 'Doe', 'M');Query OK, 1 row affected (0.01 sec)
mysql>
INSERT INTO Nicks (Nickname, FirstName, Gender)- - - >
VALUES('AussieGal', 'Shiela', 'F');Query OK, 1 row affected (0.01 sec)
mysql>
exitBye
C:\mysql\bin>
exit[/color]
[color:000066]2. USING mIRC TO ACCESS THE MySQL DATABASE[/color]; This is the quick and dirty version - no error trapping, input validation - nothing.
;alias MySQL.GetNickData {
- [/color]; Open an ADODB Connection object.
;
.comopen MySQL.Database ADODB.Connection
; For the purposes of this example, I have shortened the Open method declaration by defining a variable
; to hold a proper MySQL connection string. Again, if this step does not work for you, then you will need
; to install the OLEDB driver from here (picking the closest mirror).
;
var %Connection.String = Provider=MySQLProv;Data Source=myDatabaseName;User ID=myUsername;Password=myPassword
; Open the connection to the MySQL database you wish to work with, specified in the Data Source
; parameter above.
;
.echo -q $com(MySQL.Database, Open, 1, *bstr, %Connection.String)
; Open an ADODB Recordset object.
;
.comopen RecordsetObject ADODB.Recordset
; Again, to shorten the Open method line, I have put the SQL I want to use to populate the recordset
; inside a variable.
;
var %SQL = SELECT FirstName, LastName, Gender FROM Nicks WHERE Nickname = ' $+ $1 $+ ';
; Open the recordset object using the previously setup SQL variable on the Connection object.
;
.echo -q $com(RecordsetObject, Open, 1, *bstr, %SQL, dispatch, MySQL.Database, int, 1, int, 3, int 1)
; The Collect property is an undocumented shortcut way to grab just the value held in the fields
; which are zero-based. As you can see from the SQL above, I have specified 3 fields I wish returned:
;
; * FirstName (field 0)
; * LastName (field 1)
; * Gender (field 2)
;
; So, I grab the data from the FirstName field and store the result in the variable %Name.
;
.echo -q $com(RecordsetObject, Collect, 2, i4, 0)
var %Name = $com(RecordsetObject).result
; Then I grab the data from the LastName field and add it to the %Name variable.
;
.echo -q $com(RecordsetObject, Collect, 2, i4, 1)
var %Name = %Name $com(RecordsetObject).result
; Then I grab the Gender data and put it in its own variable, surrounded by parentheses.
;
.echo -q $com(RecordsetObject, Collect, 2, i4, 2)
var %Gender = ( $+ $com(RecordsetObject).result $+ )
; Now I can return or display the results from the database query to the active window.
;
if ($isid) return %Name %Gender
else echo -gaitc info * $1 is %Name %Gender
; And finally, (being the neat little programmer that I am) I close the two objects I have used.
;
.comclose RecordsetObject
.comclose MySQL.Database
}
/MySQL.GetNickData JDoe5•[color:#6F5B65]15:21:17[/color]
* JDoe is John Doe (M)