Jump to content

MySQL


Alek
 Share

Recommended Posts

im trying make the UDF's using .bat files and mysql.exe

this is what i got so far but it dosent work properly.

lets say i try to querry a whole table, and it returns only some of the data in the table, anyone know why not??

SELECT * FROM account

it works great if i try to query for a specific ting, like

SELECT name FROM account WHERE id=1

$Host = "localhost"
$User = "root"
$Pass = "root"
$port = "3306"
$DB = "my_db"

$Test = _MySQL_Query("SELECT * FROM table")
if Not @error then
    for $x = 1 to $Test[0]
        if $Test[$x] <> "" Then MsgBox(0,"",$Test[$x])
    Next
Else
    MsgBox(0,"",$Test)
EndIf

Func _MySQL_Query($Query)
    ;im going to set @scriptDir to @tempdir or some other dir later,this is just for testing
    FileDelete(@ScriptDir & "\temp.bat")
    FileDelete(@ScriptDir & "\temp.sql")
    FileWrite(@ScriptDir & "\temp.sql",$Query)
    FileWrite(@ScriptDir & "\Temp.bat","MYSQL -h "& $Host &" --user="& $User &" --password="& $Pass &" --port="& $port &" "& $DB &" < temp.sql")
    $MySQL = Run(@ScriptDir & "\Temp.bat", @ScriptDir, @SW_HIDE,6)
    $line = StdoutRead($MySQL)
    $line = StdoutRead($MySQL)
    While 1
        $line = StdoutRead($MySQL)
        If @error Then ExitLoop
        $Line = StringSplit($line,@CRLF)
        Return $line
    Wend

    While 1
        $line = StderrRead($MySQL)
        If @error Then ExitLoop
        SetError(1)
        Return "Error:" & $line
    Wend
EndFunc

mysql.exe, place it in the same path as the script

Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

May be these links will help you:

MySQL UDF

AutoIT MySQL and PHP

i have look at both.

the one using ODBC 3.51 is slow and you need to install ODBC 3.51 to use the application that i make

the one using php i couldent get to work properly

thats why im gonna try an make some udfs using .bat, it should be faster then odbc, atleast i hope it is, and easyer to use then the php functions.

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

First of all, You have this line twice:

$line = StdoutRead($MySQL)

And secondly, it returns all 3 columns of data when i execute your script.

Afraid i cannot replicate your problem.

How many rows of data should it return from your table?

i have $line = StdoutRead($MySQL) twice because atleast on my computer the two first StdoutRead returns usless data

and i have around 50ish rows of data

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

  • 4 months later...

Great method, but is there another way of exporting the SQL query output to a CSV file? stdoutread is not very reliable to read 1000s of lines of data. Another option is the tee mysql method but it saves the headers and tails too.

I was hoping for a cleaner way in mysql commandline to export the query to a csv.

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...