Sign in to follow this  
Followers 0

[Autoit & MYSQL] I got it !

5 posts in this topic

#1 ·  Posted (edited)

After leave the firebird solution, i search a solution for use mysql

here is a listing which work fine :

for use it, you need a MYSQL server, admin login & password and a database of course :lmao:

i think the comment are enough so if you have question write it here ;)

;Test mysql

#include <GUIConstants.au3>
#include <Constants.au3>

;change here the path to mysql.exe
CONST $path_mysql = "D:\Denis\wamp\mysql\bin\"
dim $tableau_result

$line = "";don't modify this, it's just for variable initialisation

;we create our database request (don't miss the; a the end of each command)
$sql = "use pictures;" & @CRLF  ;mysql = select the database to use
$sql = $sql & "select * from girls;";mysql = request in the base from the girls table

;launch function to create the file

; change 'root' by the mysql admin login
; if you have a password, you need to add it with -p parameter, ie :     mysql.exe -u YOURLOGIN -p YOURPASSWORD -X < 
$command_sql = $path_mysql & "mysql.exe -u root -X < " & $path_mysql & "sql_command.txt"    ; create the  mysql process
$command = Run(@ComSpec & " /c " & $command_sql, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD); execute the  mysql process

While 1; get the result returned by mysql.exe command
    $string_result = $line
    $line = StdoutRead($command)
    If @error = -1 Then ExitLoop
  ;MsgBox(0, "STDOUT read:", $line); display the entire returned result (if you want debug)

$tableau_result = _clean_mysql_return($string_result); clean and organize the result

for $boucle = 1 to $tableau_result[0];display the result of therequest
    $reponse = $tableau_result[$boucle]; each result in in the 
    MsgBox(262144,'MySQL Result','Value : ' & @lf & $reponse)

;***************************************************** FUNCTION DECLARATION ***********************************************************

func _clean_mysql_return($string_result)
; we will clean the XML format result
    $string_result = StringReplace($string_result,"<row>","")   ; delete all <row>
    $string_result = StringReplace($string_result,"</row>","")  ; delete all </row>
    $string_result = StringReplace($string_result,"<field name=",""); delete all <field name=>
    $string_result = StringReplace($string_result,"</field>",""); delete all </field>
    $string_result = StringReplace($string_result,"</resultset>",""); delete all </resultset>
    $string_result = StringReplace($string_result,">"," = ")    ; change all > in =
    $string_search = chr(34) & "id" & chr(34); = "id"       
    $position_caracter_id = StringInStr($string_result,$string_search); search the position of the first "id" in the string result
    $string_result = StringRight($string_result,StringLen($string_result) - $position_caracter_id + 1); delete all that is before the first "id"=
    $string_result = StringStripCR($string_result)              ; delete all CR
    $string_result = StringStripWS($string_result,4)            ; delete all useless space
    $string_result = StringReplace($string_result,chr(34),"")   ; delete all "
    $tableau_result = StringSplit($string_result,@CRLF)
    $tableau_result[0] = $tableau_result[0]-1                   ; delete the last element because is empty

func _create_mysql_command_file($string)
    $file = FileOpen($path_mysql & "sql_command.txt", 2);2 = Write mode (erase previous contents)
    FileWrite($file,$string); we write the command in the file


Edited by pinkfoyd

Share this post

Link to post
Share on other sites

After leave the firebird solution, i search a solution for use mysql

I'm looking for a solution for use with firebird/interbase enignes... Do you have any suggestion?

Thx in advance.

Share this post

Link to post
Share on other sites

#4 ·  Posted (edited)

I've got a library of MySQL funcs already (in my signature)

So i wouldn't call this "The one/only.."


Edited by cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: Hire The Brain Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post

Link to post
Share on other sites


I had been looking at using a command line for MySQL as @cdkid's obj commands do not seem to accet concatenation of commands.

I think , using yours, I could create a concatenated command using my SQLiteEXE functions (see in signature), with "$i_Execute=0", so the commands are created, not executed in SQLite; then used in your function.

I may need to post an update..

Best, Randall

Share this post

Link to post
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
Sign in to follow this  
Followers 0