[quote name='clearguy' post='269501' date='Nov 19 2006, 03:37 AM']Hi, the first time I was using this great UDF I got the same error, because the credentials for the SQL query weren't correct.
I think you have this error because of the 'in-query' variables, which are variables used only by au3 and that the SQL query doesn't know these variables.... How I would try :
.
The function can simply not connect to the server with your infos, check it.
that's why i'm thinking it won't work with my version of mysql (which i cant do anything about) as the username, password, database and server are all correct, and it doesn't matter whether i enter them directly or via variables same error.
Just as a side note, for anyone looking... it took me 2+ hours to discover this syntax.
When you want to assign a variable to a query, do this:
_Query($myConnectionObject, "SELECT someField FROM someTable WHERE someField = ' " & $myVariable & "' ")
The & concatenates the string, and the extra quotation marks tell the script that your variable is outside of the _Query parameter string, e.g. it substitutes the value of your $myVariable for the actual characters of $myVariable (which doesnt do anyone any good.)
If you try to pass $myVariable directly into the parameters, it will fail, and you're looking at a whole bunch of wasted time trying to figure it out. It's very easy
Next up, a simple explanation of how to convert the result of your SQL query into readable values, as opposed to the raw object returned.
The following snippet is fill in the blanks. It reads text from an input box, then tries to find that in the table/field location you specify:
(Note: This code isn't functional by itself, it's meant as an assisting reference)
Plain Text
;; this grabs the text from the input box with the handle $TextInputField
$myVariable = String(GUICtrlRead($TextInputField))
;;This is your connection definition
$connect = _MySQLConnect('MyUsername', 'MyPassword', 'Database name', 'IP, Computer name, or URL')
;; This is your query definition
$query = "SELECT someField FROM someTable WHERE someOtherField = '" & $myVariable & "' "
;; This is where the connection is actually used to run the query. The result is a raw MySQL object.
$myQueryObject = _Query($connect , $query)
;; The $myQueryObject is raw data... it must be parsed into something readable for you to use it. The With keyword is Autoit's way of handling object variables easily.
;; $myQueryObject.Fields('someField').Value tells Autoit to look at the value of the someField variable in the Fields part of the $myQueryObject object.
With $myQueryObject
While NOT .EOF;; Runs hrough all available matching values until there are none left
MsgBox(0, "", $myQueryObject.Fields('someField').Value);;displays the result of the previous SQL query in a message box
;;tells the script to move to the next matching value, if there is one, otherwise
.MoveNext
;; the While loop ends and
WEnd
;; the With statement ends as well
EndWith
This isn't functional, but it should be enlightening, at least a little bit helpful.
Thanks very very much for this UDF, cdkid, it's phenomenal.
Below is a .ZIP called "ODBC_DRIVER_SETUP" it has the au3 for driver setup, read _ReadMe_.txt to see how to make it work.
Still working on getting this to work for me, but I thought I could contribute this much. The below code is a much more efficient way to install the ODBC drivers. The exe you download from the link provided by cdkid extracts the MSI into %temp%. Run the exe, don't complete the install but go to the temp dir and copy the msi into C:\ and compile the script below.
Really really like the work and effort you've put into making this possible. My question might be 1 many newbies like me wonder.
I'm mad about PHP and MySQL and love Autoit. I've started to develop a website within my company whereby I can keep track of several different routines.
Im a ICT tech support guy, we get calls all the while and it's logged in a paper book. Im wanting to make that available on a website internally. After discovering your UDF, i thought what a good idea to make a program using Autoit that will pull up the nitty gritty details of a client machine they are reporting the problem on and post it to us using that along side the website.
I was pretty stupid to not realise that the MySQL ODBC had to be installed on every machine. Is there any other way of doing this?
Im totally new to all this ODBC business and COM. I was following a few tutorials on the Microsoft Website on making ActiveX scripts. I copied and pasted the examples and none of them worked.
Im trying to find a good solution that would incoporate the use of the website and a program.
If I created a small Autoit Script that added a record and placed it on a network drive, then ran it from workstations around the site without ODBC being installed, would it work?
I tried your UDF and was Unable to get it to work with my setup. The reason being I have mysql is running on a different port. So I modified your script, and thought I would share it with everyone else incase they ran into the same issue. This might not even be nessicary. I might have done all this and there was an easier way, but here it is if it is needed.
$sql = _MySQLConnect('root','','jotalbot_script','localhost')
If $sql = 0 Then
MsgBox(0, "Clipboard contains:", @error)
EndIf
$var = _Query($sql,"SELECT * FROM table")
With $var
While NOT .EOF;
MsgBox(0, "Value:", .Fields('col1').value)
.MoveNext
WEnd
EndWith
_MySQLEnd($sql)
And then this:
I read all forum, install all step by step... But not working
p.s. _Query($sql, "INSERT INTO `table`(`col1`,`col2`,`col3`,`col4`) VALUES ('ddd', 'sss', 'vvv', 'ttt');") - This string works perfect.
Look i f you have really a table called "table", it is something wrong in your data, I got this same message when I typed wrong request - or - a wrong table name.
I hope u guys have a solution of what i am doing wrong
Thanks, ZeroZ
p.s. here is the simple code i used
#include <mysql.au3>
$oSQL = _MySQLConnect("zerocore_test","nottellingyou","zerocore_database","http:\\www.zerocore.com")
if @error Then
MsgBox(0,"ERROR","ERROR")
EndIf
*If u thought life couldn't get worse, u meet me *<guy>What would you give my little sister to unzip ?<friend>10 bucks<guy>No, i mean like Winzip...
just use "if $result.EOF =0 then" to check if it exists.
suggestions for the udf.
a list of properties for the raw mysql object. and maby a way to use it without the dll (even some external dll is fine, but now one i need to install)
*If u thought life couldn't get worse, u meet me *<guy>What would you give my little sister to unzip ?<friend>10 bucks<guy>No, i mean like Winzip...
u could OR use the UPDATE command with a query or just overwrite the like by storing the value's, then deleting and rewriting the line with the extra code
*If u thought life couldn't get worse, u meet me *<guy>What would you give my little sister to unzip ?<friend>10 bucks<guy>No, i mean like Winzip...