Jump to content

MySQL Con Problem (newbie)


Recommended Posts

Hello!

I tryed to make a script with autoit3 (rel: May 25 2007) what is gonna update a table in a remote mysql database

first i gotta problem with the connection (still couldnt solve it) and then with updateing a field:

#include <mysql.au3>

opt("TrayIconDebug",1)

$value1 = "testusername"
$value2 = "testpassword"

$sqlcon = _MySqlConnect ('myusername','mypassword,'accountrequest','domain:port)

_AddRecord($sqlcon, 'account', $value1, $value2)

_MySQLEnd($sqlcon)

and i got always this error:

C:\Program Files\AutoIt3\Include\mysql.au3 (27) : ==> The requested action with this object has failed.:

$Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";")

$Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";")^ ERROR

Error in my_thread_global_end(): 1 threads didn't exit

>Exit code: 1 Time: 9.521

I've read in forum topics about this, but can't really understand what should i do now exactly, so i would ask your help to pass this problem.

I read also if i wanna change default port i need to modify something, but i couldnt go on :) (im really newbie to AutoIt and to any programm language, all what i could done is a clicksaver for pc games where you need to press a button lot of times - ofc from tutorials and from forum help - .

ps: i've read the MySQL UDF topics and SQLite, but couldnt really understand how to use em, thats why im asking for help, not because im lazy to use "search" fuction in forum.

All help is welcome, thanks in advance!

Link to comment
Share on other sites

Hey I don't know if sqlite relates but here is some working code that I have been putting together with the help of boardmembers

It creates a db if one doesn't exsist. -or opens connection if it does -you can change the path as you like

It shows how to add a table.

It shows how to add info to the table

How to query the table

It shows how update the table . . .

Its a work in progress so not much documentation yet. Let me know if you don't understand parts. I just learned most last week! :)

CODE
#include <SQLite.au3>

#include <SQLite.dll.au3>

#include <GuiConstants.au3>

#include <file.au3>

;************************************************************************

;Start

;************************************************************************

$UserName = StringUpper(@UserName)

Dim $UpdateMsg, $sMsg2, $bRecords, $ProfileForm1

Global $hDB, $hQuery, $aRow, $sMsg, $aNames

Global $avSampleData[1] = [$UserName & "," & $UserName & "," & "Empty,Empty,Empty,Empty,Empty,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26"]

;************************************************************************

;START OR CREATE SQL.DB

;************************************************************************

Global $SqlLiteDll = _SQLite_Startup()

If @error Then

MsgBox(16, "Error", "Failed to start up SQLite, @error = " & @error)

Else

;$hDB = _SQLite_Open() ; Opens a database in memory

$hDB = _SQLite_Open(@ScriptDir & "\TestData.db") ; Opens a database file to read/write

If $hDB = 0 Or @error Then

MsgBox(16, "Error", "Error opening database in memory, @error = " & @error & ", @extended = " & @extended)

Else

; Create a database table

$sExec = "CREATE TABLE Users (User_ID INTEGER PRIMARY KEY,User_Name,Full_Name,Department,I_Extention,R_Extention,Business_Cell,Email,Comment,LogOn,LogOff,

Eleven,Twelve,Thirteen,Fourteen,FIfteen,Sixteen,Seventeen,Eighteen,Ninteen,Twenty,Twentyone,Twentytw

o,Twentythree,Twentyfour,Twentyfive,Twentysix);"

_SQLite_Exec($hDB, $sExec)

;************************************************************************

; Add users

;************************************************************************

For $n = 0 To UBound($avSampleData) - 1

$avSplit = StringSplit($avSampleData[$n], ",")

; Strip leading and trailing whitespace before using entries

For $i = 1 To $avSplit[0]

$avSplit[$i] = StringStripWS($avSplit[$i], 1 + 2)

Next

$sQuery = "SELECT User_Name FROM Users WHERE User_Name='" & $UserName & "'"

_SQLite_QuerySingleRow($hDB, $sQuery, $aRow)

If $aRow[0] <> "" Then

ConsoleWrite("Debug: Skipped adding user, already exists: " & $UserName & @LF)

Else

$sExec = "INSERT INTO Users(User_Name,Full_Name,Department,I_Extention,R_Extention,Business_Cell,Email,Comment,LogOn,LogOf

f,Eleven,Twelve,Thirteen,Fourteen,FIfteen,Sixteen,Seventeen,Eighteen,Ninteen,Twenty,Twentyone,Twenty

two,Twentythree,Twentyfour,Twentyfive,Twentysix) VALUES('" & $avSplit[1] & "','" & $avSplit[2] & "','" & $avSplit[3] & "','" & $avSplit[4] & "','" & $avSplit[5] & "','" & $avSplit[6] & "','" & $avSplit[7] & "','" & $avSplit[8] & "','" & $avSplit[9] & "','" & $avSplit[10] & "','" & $avSplit[11] & "','" & $avSplit[12] & "','" & $avSplit[13] & "','" & $avSplit[14] & "','" & $avSplit[15] & "','" & $avSplit[16] & "','" & $avSplit[17] & "','" & $avSplit[18] & "','" & $avSplit[19] & "','" & $avSplit[20] & "','" & $avSplit[21] & "','" & $avSplit[22] & "','" & $avSplit[23] & "','" & $avSplit[24] & "','" & $avSplit[25] & "','" & $avSplit[26] & "');"

If _SQLite_Exec($hDB, $sExec) = $SQLITE_OK Then ConsoleWrite("Debug: Successfully added to Users table: " & $avSplit[2] & @LF)

EndIf

Next

;************************************************************************

; Make a record change

;************************************************************************

;_QueryMarketing() ; Show current data

;$sExec = "UPDATE Users SET Department='Marketing' WHERE User_Name='" & $UserName & "'" ; Change a record

;If _SQLite_Exec($hDB, $sExec) = $SQLITE_OK Then ConsoleWrite("Debug: Successfully updated a record." & @LF)

;_QueryMarketing(); Show data again

;************************************************************************

;Building of GUI Users logged On Array

;************************************************************************

; Query the database to add Users to GUI

$sQuery = 'SELECT User_Name,Full_Name FROM Users WHERE User_Name="' & $UserName & '"'

If _SQLite_Query(-1, $sQuery, $hQuery) = $SQLITE_OK Then

; Read data out of the query

While 1

$RET = _SQLite_FetchData($hQuery, $aRow)

If $RET = $SQLITE_OK Then

$sMsg &= $aRow[0] & ","

$sMsg2 &= $aRow[1] & ","

Else

ExitLoop

EndIf

WEnd

If StringRight($sMsg, 1) = "," Then $sMsg = StringTrimRight($sMsg, 1)

$aRecords = StringSplit($sMsg, ",")

If StringRight($sMsg2, 1) = "," Then $sMsg2 = StringTrimRight($sMsg2, 1)

$bRecords = StringSplit($sMsg2, ",")

Else

MsgBox(16, "Error", "Error executing query: " & $sQuery)

EndIf

; Shut it down

_SQLite_Close($hDB)

_SQLite_Shutdown()

EndIf

EndIf

; Debug check of data -Shows matching

;_ArrayDisplay($aRecords, "Debug: $aRecords")

;_ArrayDisplay($bRecords, "Debug: $bRecords")

;MsgBox(64, "Results", $sMsg)

Dim $aButtons[$aRecords[0] + 1]

;Dim $aButtons[uBound($aRecords)]

$aHeight = (($aRecords[0] + 1) * 25) + 100

; START NET SEND

RunWait("net start messenger", "", @SW_HIDE)

;************************************************************************

;CREATE $ParentWin GUI and Add Options

;************************************************************************

; GUI

$ParentWin = GUICreate(@UserName & "'s Messenger", 250, $aHeight, 440, 360)

GUISetIcon(@SystemDir & "\mspaint.exe", 0)

; MENU

$filemenu = GUICtrlCreateMenu("File")

$UpdateProfile = GUICtrlCreateMenuItem("Update Profile", $filemenu)

$separator1 = GUICtrlCreateMenuItem("", $filemenu)

$exititem = GUICtrlCreateMenuItem("Exit", $filemenu)

;LABEL - TO BE ADDED WITH USERID DETAIL

$CurrentUserName = GUICtrlCreateLabel("Type Message *Press Button to Send*", 20, 10, 200, 20)

; INPUT

$Edit1 = GUICtrlCreateEdit("Type Message Here", 10, 30, 230, 60, $ES_WANTRETURN)

;BUILD BUTTONS

$aTop = 100

$aLeft = 10

For $x = 1 To $bRecords[0]

$aButtons[$x] = GUICtrlCreateButton($bRecords[$x], $aLeft, $aTop, 100, 30)

If $aLeft = 10 Then

$aLeft = 140

ContinueLoop

Else

$aLeft = 10

$aTop = $aTop + 40

EndIf

Next

;************************************************************************

;START WHILE LOOP

;************************************************************************

GUISetState()

While 1

$msg = GUIGetMsg()

; Clear the Edit Box on Click

$cursorinfo = GUIGetCursorInfo($ParentWin)

If $cursorinfo[4] = $Edit1 Then

If $cursorinfo[2] = 1 Then

GUICtrlSetData($Edit1, "")

EndIf

EndIf

;Set Exits

If $msg = $GUI_EVENT_CLOSE Then Exit

If $msg = $exititem Then Exit

;************************************************************************

;CREATE $UpdateProfile GUI

;************************************************************************

If $msg = $UpdateProfile Then

$Form1 = GUICreate("Update Profile", 780, 380)

$Input1 = GUICtrlCreateInput("1", 8, 32, 50, 21)

$Input2 = GUICtrlCreateInput("2", 74, 32, 50, 21)

$Input3 = GUICtrlCreateInput("3", 140, 32, 50, 21)

$Input4 = GUICtrlCreateInput("4", 206, 32, 100, 21)

$Input5 = GUICtrlCreateInput("5", 8, 88, 150, 21)

$Input6 = GUICtrlCreateInput("6", 174, 88, 150, 21)

$Input7 = GUICtrlCreateInput("7", 8, 144, 400, 21)

$Label1 = GUICtrlCreateLabel("Department:", 8, 8, 60, 17)

$Label2 = GUICtrlCreateLabel("I Extention:", 74, 8, 60, 17)

$Label3 = GUICtrlCreateLabel("R Extention:", 140, 8, 60, 17)

$Label4 = GUICtrlCreateLabel("Business Cell:", 206, 8, 70, 17)

$Label5 = GUICtrlCreateLabel("Full Name:", 8, 64, 54, 17)

$Label6 = GUICtrlCreateLabel("Email:", 174, 64, 54, 17)

$Label7 = GUICtrlCreateLabel("Comment:", 8, 120, 51, 17)

$Label8 = GUICtrlCreateLabel("title", 125, 180, 47, 17)

$Label9 = GUICtrlCreateLabel("title", 475, 180, 51, 17)

$Label10 = GUICtrlCreateLabel("title", 475, 262, 75, 17)

$Label11 = GUICtrlCreateLabel("title", 125, 262, 111, 17)

$Checkbox1 = GUICtrlCreateCheckbox("1", 8, 200, 170, 17)

$Checkbox2 = GUICtrlCreateCheckbox("2", 8, 220, 170, 17)

$Checkbox5 = GUICtrlCreateCheckbox("3", 194, 200, 170, 17)

$Checkbox6 = GUICtrlCreateCheckbox("4", 194, 220, 170, 17)

$Checkbox3 = GUICtrlCreateCheckbox("5", 8, 284, 170, 17)

$Checkbox4 = GUICtrlCreateCheckbox("6", 8, 304, 170, 17)

$Checkbox7 = GUICtrlCreateCheckbox("7", 194, 284, 170, 17)

$Checkbox8 = GUICtrlCreateCheckbox("8", 194, 304, 170, 17)

$Checkbox9 = GUICtrlCreateCheckbox("9", 380, 200, 170, 17)

$Checkbox10 = GUICtrlCreateCheckbox("10", 380, 220, 170, 17)

$Checkbox13 = GUICtrlCreateCheckbox("11", 566, 200, 170, 17)

$Checkbox14 = GUICtrlCreateCheckbox("12", 566, 220, 170, 17)

$Checkbox11 = GUICtrlCreateCheckbox("13", 380, 284, 170, 17)

$Checkbox12 = GUICtrlCreateCheckbox("14", 380, 304, 170, 17)

$Checkbox15 = GUICtrlCreateCheckbox("15", 566, 284, 170, 17)

$Checkbox16 = GUICtrlCreateCheckbox("16", 566, 304, 170, 17)

$UpdateProfileButton = GUICtrlCreateButton("Update", 700, 350, 75, 25, 0)

Global $SqlLiteDll = _SQLite_Startup()

If @error Then

MsgBox(16, "Error", "Failed to start up SQLite, @error = " & @error)

Else

$hDB = _SQLite_Open(@ScriptDir & "\TestData.db") ; Opens a database file to read/write

If $hDB = 0 Or @error Then

MsgBox(16, "Error", "Error opening database in memory, @error = " & @error & ", @extended = " & @extended)

Else

; Query the database to add Users to GUI

$sQuery = 'SELECT User_Name,Full_Name,Department,I_Extention,R_Extention,Business_Cell,Email,Comment,LogOn,LogOff,Elev

en,Twelve,Thirteen,Fourteen,FIfteen,Sixteen,Seventeen,Eighteen,Ninteen,Twenty,Twentyone,Twentytwo,Tw

entythree,Twentyfour,Twentyfive,Twentysix FROM Users WHERE User_Name="' & $UserName & '"'

If _SQLite_Query(-1, $sQuery, $hQuery) = $SQLITE_OK Then

; Read data out of the query

While 1

$RET = _SQLite_FetchData($hQuery, $aRow)

If $RET = $SQLITE_OK Then

GUICtrlSetData($Input1, $aRow[2]) ;Department

GUICtrlSetData($Input2, $aRow[3]) ;I_Extention

GUICtrlSetData($Input3, $aRow[4]) ;R_Extention

GUICtrlSetData($Input4, $aRow[5]) ;Business_Cell

GUICtrlSetData($Input5, $aRow[1]) ;Full_Name

GUICtrlSetData($Input6, $aRow[6]) ;Email

GUICtrlSetData($Input7, $aRow[7]) ;Comment

Else

ExitLoop

EndIf

WEnd

Else

MsgBox(16, "Error", "Error executing query: " & $sQuery)

EndIf

; Shut it down

_SQLite_Close($hDB)

_SQLite_Shutdown()

EndIf

EndIf

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

If $nMsg = $GUI_EVENT_CLOSE Then

GUIDelete($ProfileForm1)

ExitLoop

EndIf

If $nMsg = $UpdateProfileButton Then

Global $SqlLiteDll = _SQLite_Startup()

If @error Then

MsgBox(16, "Error", "Failed to start up SQLite, @error = " & @error)

Else

$hDB = _SQLite_Open(@ScriptDir & "\TestData.db") ; Opens a database file to read/write

If $hDB = 0 Or @error Then

MsgBox(16, "Error", "Error opening database in memory, @error = " & @error & ", @extended = " & @extended)

Else

; Create a database table

$sExec = "CREATE TABLE Users (User_ID INTEGER PRIMARY KEY,User_Name,Full_Name,Department,I_Extention,R_Extention,Business_Cell,Email,Comment,LogOn,LogOff,

Eleven,Twelve,Thirteen,Fourteen,FIfteen,Sixteen,Seventeen,Eighteen,Ninteen,Twenty,Twentyone,Twentytw

o,Twentythree,Twentyfour,Twentyfive,Twentysix);"

_SQLite_Exec($hDB, $sExec)

$sExec = "UPDATE Users SET Department='" & GUICtrlRead($Input1) & "' WHERE User_Name='" & $UserName & "'" ; Change a record

If _SQLite_Exec($hDB, $sExec) = $SQLITE_OK Then ConsoleWrite("Debug: Successfully updated a record." & @LF)

$sExec = "UPDATE Users SET I_Extention='" & GUICtrlRead($Input2) & "' WHERE User_Name='" & $UserName & "'" ; Change a record

If _SQLite_Exec($hDB, $sExec) = $SQLITE_OK Then ConsoleWrite("Debug: Successfully updated a record." & @LF)

$sExec = "UPDATE Users SET R_Extention='" & GUICtrlRead($Input3) & "' WHERE User_Name='" & $UserName & "'" ; Change a record

If _SQLite_Exec($hDB, $sExec) = $SQLITE_OK Then ConsoleWrite("Debug: Successfully updated a record." & @LF)

$sExec = "UPDATE Users SET Business_Cell='" & GUICtrlRead($Input4) & "' WHERE User_Name='" & $UserName & "'" ; Change a record

If _SQLite_Exec($hDB, $sExec) = $SQLITE_OK Then ConsoleWrite("Debug: Successfully updated a record." & @LF)

$sExec = "UPDATE Users SET Full_Name='" & GUICtrlRead($Input5) & "' WHERE User_Name='" & $UserName & "'" ; Change a record

If _SQLite_Exec($hDB, $sExec) = $SQLITE_OK Then ConsoleWrite("Debug: Successfully updated a record." & @LF)

$sExec = "UPDATE Users SET Email='" & GUICtrlRead($Input6) & "' WHERE User_Name='" & $UserName & "'" ; Change a record

If _SQLite_Exec($hDB, $sExec) = $SQLITE_OK Then ConsoleWrite("Debug: Successfully updated a record." & @LF)

$sExec = "UPDATE Users SET Comment='" & GUICtrlRead($Input7) & "' WHERE User_Name='" & $UserName & "'" ; Change a record

If _SQLite_Exec($hDB, $sExec) = $SQLITE_OK Then ConsoleWrite("Debug: Successfully updated a record." & @LF)

MsgBox(64, "Profile Update Compete", "Your UserProfile has been updated.")

EndIf

EndIf

; Shut it down

_SQLite_Close($hDB)

_SQLite_Shutdown()

EndIf

WEnd

EndIf

;************************************************************************

;SET Action to $ParentWin Array Generated Users

;************************************************************************

; Set User List (Buttons for now)

For $x = 1 To $aRecords[0]

If $msg = $aButtons[$x] Then

Run("net send " & $aRecords[$x] & " Mesage From " & @UserName & ": " & StringReplace(GUICtrlRead($Edit1), @CRLF, " "), "", @SW_HIDE)

MsgBox(0, "Message Sent", "message to " & $aRecords[$x] & ": " & StringReplace(GUICtrlRead($Edit1), @CRLF, " "))

EndIf

Next

WEnd

;************************************************************************

;FUNCTIONS

;************************************************************************

Func _QueryMarketing()

; Query for users in Marketing

$sQuery = "SELECT * FROM Users WHERE Department='Marketing'" ;To be changed to logon where logon > logoff and logon > (now - x)

If _SQLite_Query($hDB, $sQuery, $hQuery) = $SQLITE_OK Then

; Read data out of the query

$UpdateMsg = "Marketing users:" & @LF

While 1

$RET = _SQLite_FetchData($hQuery, $aRow)

If $RET = $SQLITE_OK Then

ConsoleWrite("Debug: FetchData loop got one row of data..." & @LF)

$UpdateMsg &= $aRow[2] & @CRLF

Else

ConsoleWrite("Debug: Exit FetchData loop, $RET = " & $RET & @LF)

ExitLoop

EndIf

WEnd

MsgBox(64, "Results", $UpdateMsg)

Else

MsgBox(16, "Error", "Error executing query: " & $sQuery)

EndIf

EndFunc ;==>_QueryMarketing

Most of the debug info is turned off because I have worked throught it.

This is intended as a how to, not a direct answer to your issues :P

Edited by Hatcheda
Link to comment
Share on other sites

Thanks for the tip and answer, but as i can see its not the one what im searching for (or at least i couldn't find the part what i would like to find), couldn find the "connection" part in the code, where it connects to remote database, as i see its only create new, but not connecting to remote one and thats my problem for now. As i can see from script comments like "Opens a database file to read/write" it works with colcal files, handling them as database.

edit: yeah, i forgot to write, remote mysql database

Edited by Stormrage
Link to comment
Share on other sites

Your right about it creating a database, but it checks if it exsists first. If it does, then it doesn't create it, it just connects. As for the path, that can be changed to where ever you want. Since I am still working on the GUI, I have not changed to connection path :P

I would suggest that you make PsaltyDS aware of your issue. He has helped me through most of mine and might find your issue on his "easy to do" list. :)

Link to comment
Share on other sites

? what/who is it/he/she? and where is that Easy to do list?

PsaltyDS = a rakishly handsome flightless antarctic water fowl, who is learning to use AutoIt's SQLite functions, and has helped Hatcheda with the same.

The problem is SQLite != MySQL. So he may not be of much use.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Not speaking from any MySQL experience here, but --

Here's the relevant portion of MySQL.au3:

#cs
    Function Name:    _MySQLConnect
    Description:      Initiate a connection to a MySQL database.
    Parameter(s):     $username - The username to connect to the database with.
    $password - The password to connect to the database with. $Database - Database to connect to.
    $server - The server your database is on.
    $driver (optional) the ODBC driver to use (default is "{MySQL ODBC 3.51 Driver}"
    Requirement(s):   Autoit 3 with COM support
    Return Value(s):  On success returns the connection object for subsequent functions. On failure returns 0 and sets @error
    @Error = 1
    Error opening connection
    @Error = 2
    MySQL ODBC Driver not installed.
    Author(s):        cdkid
#ce

Func _MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer, $sDriver = "{MySQL ODBC 3.51 Driver}")
    Local $v = StringMid($sDriver, 2, StringLen($sDriver) - 2)
    Local $key = "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers", $val = RegRead($key, $v)
    If @error Or $val = "" Then
        SetError(2)
        Return 0
    EndIf
    $ObjConn = ObjCreate("ADODB.Connection")
    $ObjConn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";")
    If @error Then
        SetError(1)
        Return 0
    Else
        Return $ObjConn
    EndIf
EndFunc   ;==>_MySQLConnectoÝ÷ ØÚ-zØ^r¦z{l±ç-ÚnÞ¶ºw-ÌÉ$
çyËr¢éÞyÛhµë-~Þ®º+^®»§)àÖ§uë)yÈ¥¢¢·«®

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

problem is that, cant even "build" it, because i always got this error:

C:\Program Files\AutoIt3\Include\mysql.au3 (27) : ==> The requested action with this object has failed.:

$Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";PORT=" & $sPort & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";")

$Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";PORT=" & $sPort & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";")^ ERROR

Error in my_thread_global_end(): 1 threads didn't exit

and dunno how to run MySQL thingy, i installed it (full install), but couldn find any icon or so

Edited by Stormrage
Link to comment
Share on other sites

problem is that, cant even "build" it, because i always got this error:

Build it...? Build what? :P

and dunno how to run MySQL thingy, i installed it (full install), but couldn find any icon or so

Full install...? Full install of what? :)

Perhaps I missed what you are trying to do. The OP was about updating a table on a remote MySQL database server. Is that still what we're talking about here?

If it is, the first thing to do is ensure you have installed a MySQL ODBC driver. Is that done? Did you test for @error after the _MySqlConnect(), as I posted earlier? What were the results?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

yes, i have installed MySQL ODBC driver and the problem is that, i cant run the script, because its givin the error, what ive posted above

#include <mysql.au3>

Opt("TrayIconDebug", 1)

$value1 = "testusername"
$value2 = "testpassword"

$sqlcon = _MySqlConnect ('uname', 'pass', 'db, 'domain')
If Not @error Then
    _AddRecord ($sqlcon, 'account', $value1, $value2)
;   $dbs = _GetDbNames($sqlcon)
;   For $i in $dbs
;   MsgBox(0,'',$i)
;   Next
Else
    MsgBox(16, "Error", "_MySqlConnect() returned @error = " & @error)
EndIf

_MySQLEnd ($sqlcon)

tryed to count db (it should work anyways, coz dun need update table) but thats not working too, no msg box appear as it should, only i got the error line in SciTE.

Edited by Stormrage
Link to comment
Share on other sites

finally!!!!!!!!! finally made it work, i got error 2

Made it work, got error 2...

...and today's secret word, kids, is OXYMORON.

:P

Did you get your actual connection working, or just get the error reporting to work? If the error MsgBox() is reporting @error = 2 from _MySqlConnect(), then we are still talking about an issue with your MySQL ODBC driver. If you run the ODBCAD32.exe utility and look at the Drivers tab, is your driver listed?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

dun have such exe running, not even installed with Mysql ODBC driver...

just get to error reporting, but oculdnt make connection yet

ODBCAD32.EXE is a windows component. You should see it in Administrative Tools, as Data Sources (ODBC).

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

okay, but what now then? :S

Here's the issue (as far as I can tell):

1. You are getting @error = 2 when you do _MySqlConnect().

2. According to the listing, that indicates the MySQL ODBC driver was invalid.

3. You said, however, that you installed the driver.

4. The place to verify that, and to find out how the driver is named for use in the last parameter of _MySqlConnect(), is the ODBCAD32.EXE utility.

On point (1.): Are you getting @error = 2 back from _MySqlConnect()? Or have I misunderstood?

On point (4.): Exactly what version is installed? The default driver name is "{MySQL ODBC 3.51 Driver}". Note the function declaration in the _MySQL.au3 listing:

#cs
    Function Name:    _MySQLConnect
    Description:      Initiate a connection to a MySQL database.
    Parameter(s):     $username - The username to connect to the database with.
    $password - The password to connect to the database with. $Database - Database to connect to.
    $server - The server your database is on.
    $driver (optional) the ODBC driver to use (default is "{MySQL ODBC 3.51 Driver}"
    Requirement(s):   Autoit 3 with COM support
    Return Value(s):  On success returns the connection object for subsequent functions. On failure returns 0 and sets @error
    @Error = 1
    Error opening connection
    @Error = 2
    MySQL ODBC Driver not installed.
    Author(s):        cdkid
#ce

Func _MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer, $sDriver = "{MySQL ODBC 3.51 Driver}")
    Local $v = StringMid($sDriver, 2, StringLen($sDriver) - 2)
    Local $key = "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers", $val = RegRead($key, $v)
    If @error or $val = "" Then
        SetError(2)
        Return 0
    EndIf
    $ObjConn = ObjCreate("ADODB.Connection")
    $Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";")
    If @error Then
        SetError(1)
        Return 0
    Else
        Return $ObjConn
    EndIf
EndFunc   ;==>_MySQLConnectoÝ÷ Ù8b²f²m溧¶R£  塧^vØ^rêëz{i®nrبÌ@·k÷«jwb¶ÈhÂË©{axàÁ
Ú(«*ºLÉ$80BßC®+Þ®«¨µµLsNØ^rêåɺÚqë?lêíç.®­§²f²mì!jØZ¦§³^*.ºÇ®®

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

yes, its returning @error = 2 and i have installed with that installer the mysql-connector-odbc-3.51.17-win32

now tryed with your code, but im still gettin the same (i tryed it with several mysql server)

Well, the server shouldn't be the issue. If that was wrong you should get @error = 1. All this discussion of the ODBC driver comes from @error = 2. What is the exact title listed on the Drivers tab of ODBCAD32.exe?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

its exactly what you told in script

Well, we've exhausted what I know of the topic (which isn't saying much). Clue donations welcome...

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...