Jump to content

Recommended Posts

Posted (edited)

First of all, thanks to ProgAndy MySQL UDFs. If you do not have it, you should check it out. Nice tool.

Coding with v3.3.0.0, here's what you guyz can test:

#include <Array.au3>
#include <File.au3>
#include <mysql.au3>

$sServerName = "nameserver"
$sUser = "user"
$sPassword = "password"
$sDatabase = "database"
$iPort = "3306"; default MySQL Port=3306

_MySQL_InitLibrary()

If @error Then 
    MsgBox(0, '', "")
    Exit
EndIf


$MysqlConn = _MySQL_Init()

$connected = _MySQL_Real_Connect($MysqlConn, $sServerName, $sUser, $sPassword, $sDatabase, $iPort)

If $connected = 0 Then
    MsgBox(0, "_MySQL_Real_Connect", "Status: " & $connected)
    Exit
EndIf


$query = "SELECT * FROM table"
_MySQL_Real_Query($MysqlConn, $query)
ToolTip("Current query: " & $query,0,0, "Connection: " & $sUser & "@" & $sServerName & ":" & $iPort & " / " & $sDatabase,1)

$res = _MySQL_Store_Result($MysqlConn)
$fields = _MySQL_Num_Fields($res)
$rows = _MySQL_Num_Rows($res)

MsgBox(0, "Data Information","_MySQL_Num_Rows: " & $rows & @CRLF & "_MySQL_Num_Fields: " & $fields)


MsgBox(0, '', "Accessed method 3 - everything in a 2D array")
$array = _MySQL_Fetch_Result_StringArray($res)

$avData =  _ArrayDisplay($array,""); Result is perfect in here. I want to send data from Array into a txt/csv file.
MsgBox(0, "_ArrayDisplay", $avData); Result shown here $avData = '1'.

; Query release
_MySQL_Free_Result($res)
;~ MsgBox(0,"_MySQL_Free_Result","_MySQL_Free_Result: " & $res)


; Connection terminate
_MySQL_Close($MysqlConn)
; MYSQL terminate
_MySQL_EndLibrary()

The _ArrayDisplay's perfect, but I'm trying to :

  • Get this data out of the array dumping it to a file without copying manually to clipboard. Data will be sent later via email, maybe attachment file or something.

Focusing on lines

$avData =  _ArrayDisplay($array,""); Result is perfect in here. I want to send data from Array into a txt/csv file.
MsgBox(0, "_ArrayDisplay", $avData); Result shown here $avData = '1'.

Has you can see '$avData' returns '1'...

I've tried

_FileWriteFromArray("D:\test.txt", $avData, 1); does not work :(

Any suggestions ?

Edited by M a k a v e l !

[font="Lucida Sans Unicode"]M a k. a v e L ![/font]

Posted

Focusing on lines

$avData =  _ArrayDisplay($array,""); Result is perfect in here. I want to send data from Array into a txt/csv file.
MsgBox(0, "_ArrayDisplay", $avData); Result shown here $avData = '1'.

Has you can see '$avData' returns '1'...

I've tried

_FileWriteFromArray("D:\test.txt", $avData, 1); does not work :(

Any suggestions ?

The '1' is just telling you _ArrayDisplay() succeeded. I don't understand why you are trying to do anything else with that return value, and it's not an array, so you can't write it with _FileWriteFromArray().

Even if you tried to write $array, isn't that a 2D array? You can only write a 1D array with _FileWriteFromArray(), and that won't custom format it as a .CSV for you.

You will have to do your own function to take each row from $array, format it as desired, and write it to the file.

Another option is to use the _Excel* functions with Excel. Then you can make changes to a sheet and save it in .csv format, letting Excel deal with the conversion.

:)

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
Posted

The '1' is just telling you _ArrayDisplay() succeeded. I don't understand why you are trying to do anything else with that return value, and it's not an array, so you can't write it with _FileWriteFromArray().

Success: Returns a 1. That I know.

Even if you tried to write $array, isn't that a 2D array? You can only write a 1D array with _FileWriteFromArray()

I didn't know it is only for 1D arrays, thanks for the hint.

I'm workin' on it.

[font="Lucida Sans Unicode"]M a k. a v e L ![/font]

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
  • Recently Browsing   0 members

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