mIRC Home    About    Download    Register    News    Help

Print Thread
#110261 05/02/05 04:45 PM
Joined: Jan 2005
Posts: 28
G
Godlike Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jan 2005
Posts: 28
Ok i would like to insert something from mirc text in chans to mysql database.

I have mysql server and already using some db for other purposes, i created new db and tables i will use. Now i would like to insert data into it.

I would get data from some mirc channel.

I`ll gather data with ON *:TEXT ...... and store the lines to one var with $1- .....
Then whe i have this stored i need to connect to mysql and execute query to insert this data into one table.

So what i need is just the code for mysql connect, and how to use queries in mirc script to insert data to my db.

Note that i have all privileges and everything in mysql db.

Thanx for your help.

#110262 05/02/05 05:14 PM
Joined: Jan 2005
Posts: 28
G
Godlike Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jan 2005
Posts: 28
And one more question how can i read this:

--->>>> --- HELLO --- <<<<<----- im a very big person indeed

and i would like to store word hello in one var i would do:

set %var $3
so %var would conatin word 'HELLO'

but how can i store 'im a very big person indeed' in other var....

the $1- reads the whole line
and id like to have %var1 containing 'im a very big person indeed'

and for exmp. i have stored in variable something like this -hi-
how can i delete char - form it so i would get only 'hi' in other var then ?

Last edited by Godlike; 05/02/05 05:21 PM.
#110263 05/02/05 07:55 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
If you want to use just mIRC scripting to accomplish this, then the easiest approach is to use an ADODB.Connection object and an ADODB.Command object to just INSERT INTO tablename. For speed purposes, you'll want to keep both objects open as long as that script is in operation, rather than opening the two objects each time.

To open the two objects:
  • .comopen MySQL ADODB.Connection
    .comopen MyCommand ADODB.Command
Then you need to create your connection string, using either:
  • var %ConnectionString = DRIVER={MySQL ODBC 3.51 Driver};Port=3306;Option=16384;Stmt=;Database=dbname;Server=12.34.56.78;User ID=username;Password=passWORD
or
  • var %ConnectionString = Provider=MySQLProv;Data Source=dbname;Server=localhost;User ID=username;Password=passWORD
Then you use the Open() method of the Connection object:
  • .echo -q $com(MySQL, Open, 1, *bstr, %ConnectionString)
Then you store the active connection in the ActiveConnection property of the Command object.
  • .echo -q $com(MyCommand, ActiveConnection, 4, dispatch, MySQL)
This ends the persistent part. When you get ready to shut down mIRC, you can close both objects.
  • .comclose MyCommand
    .echo -q $com(MySQL, Close, 1)
    .comclose MySQL
Now in your on TEXT event, you simply use the MyCommand object normally. Store the SQL you want in a variable first (to avoid comma problems, mainly). Then you can put the contents of that variable in the CommandText property and use the Execute method to send it to MySQL.

on *:TEXT:MySQL *:#:{
  • var %SQL = INSERT INTO table_name (when, nick, text) VALUES (NOW(), $nick , $2- )
    .echo -q $com(MyCommand, CommandText, 4, *bstr, %SQL)
    .echo -q $com(MyCommand, Execute, 1)
}

IMPORTANT NOTE: In the above explanation, there is NO error checking done at any point, and there should be.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#110264 05/02/05 07:59 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
--->>>> --- HELLO --- <<<<<----- im a very big person indeed

$1 = --->>>>
$2 = ---
$3 = HELLO
$4 = ---
$5 = <<<<<-----
$6- = im a very big person indeed

The - after the $6 means "from the sixth 'word' to the end of the string."


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#110265 05/02/05 08:31 PM
Joined: Jan 2005
Posts: 28
G
Godlike Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jan 2005
Posts: 28
thx.

One more thing how can i insert time when something is added to my db in UNIX timestamp as INT, i already made table 'timestamp' which is INT, how do i convert to this format ?

#110266 06/02/05 07:57 AM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
var %SQL = INSERT INTO table_name (timestamp) VALUES ( $ctime )


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#110267 06/02/05 05:00 PM
Joined: Jan 2005
Posts: 28
G
Godlike Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jan 2005
Posts: 28
I have done it like this:

Code:

on *:TEXT:*help*:#:{
  .comopen MySQL ADODB.Connection 
  .comopen MyCommand ADODB.Command
  var %ConnectionString = Provider=MySQLProv;Data Source=help;Server=localhost;User ID=root;Password=pass
  .echo -q $com(MySQL, Open, 1, *bstr, %ConnectionString)
  .echo -q $com(MyCommand, ActiveConnection, 4, dispatch, MySQL)
  set %name $2
  set %section $3
  /aline -p @test %name %section
  var %SQL = INSERT INTO table (name,type,timestamp) VALUES ( %name, %type , $ctime ) 
  .echo -q $com(MyCommand, CommandText, 4, *bstr, %SQL) 
  .echo -q $com(MyCommand, Execute, 1)
  .comclose MyCommand 
  .echo -q $com(MySQL, Close, 1) 
  .comclose MySQL
}


and doesnt work frown

Last edited by Godlike; 06/02/05 05:11 PM.

Link Copied to Clipboard