-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.au3
94 lines (72 loc) · 2.77 KB
/
test.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.2.8.1 (beta)
Author: Prog@ndy
Script Function:
MySQL-Plugin Demo Script
#ce ----------------------------------------------------------------------------
#include <array.au3>
#include "mysql.au3"
; MYSQL starten, DLL im PATH (enthält auch @ScriptDir), sont Pfad zur DLL angeben. DLL muss libmysql.dll heißen.
_MySQL_InitLibrary()
If @error Then Exit MsgBox(0, '', "")
MsgBox(0, "DLL Version:",_MySQL_Get_Client_Version()&@CRLF& _MySQL_Get_Client_Info())
$MysqlConn = _MySQL_Init()
;Fehler Demo:
MsgBox(0,"Fehler-Demo","Fehler-Demo")
$connected = _MySQL_Real_Connect($MysqlConn,"localhostdfdf","droot","","cdcol")
If $connected = 0 Then
$errno = _MySQL_errno($MysqlConn)
MsgBox(0,"Error:",$errno & @LF & _MySQL_error($MysqlConn))
If $errno = $CR_UNKNOWN_HOST Then MsgBox(0,"Error:","$CR_UNKNOWN_HOST" & @LF & $CR_UNKNOWN_HOST)
Endif
; XAMPP cdcol
MsgBox(0, "XAMPP-Cdcol-demo", "XAMPP-Cdcol-demo")
$connected = _MySQL_Real_Connect($MysqlConn, "localhost", "root", "", "cdcol")
If $connected = 0 Then Exit MsgBox(16, 'Connection Error', _MySQL_Error($MysqlConn))
$query = "SELECT * FROM cds"
_MySQL_Real_Query($MysqlConn, $query)
$res = _MySQL_Store_Result($MysqlConn)
$fields = _MySQL_Num_Fields($res)
$rows = _MySQL_Num_Rows($res)
MsgBox(0, "", $rows & "-" & $fields)
; Zugriff 1
MsgBox(0, '', "Zugriff Methode 1- Handarbeit")
Dim $array[$rows][$fields]
For $k = 1 To $rows
$mysqlrow = _MySQL_Fetch_Row($res,$fields)
$lenthsStruct = _MySQL_Fetch_Lengths($res)
For $i = 1 To $fields
$length = DllStructGetData($lenthsStruct, 1, $i)
$fieldPtr = DllStructGetData($mysqlrow, 1, $i)
$data = DllStructGetData(DllStructCreate("char[" & $length & "]", $fieldPtr), 1)
$array[$k - 1][$i - 1] = $data
Next
Next
_ArrayDisplay($array)
; Zugriff 2
MsgBox(0, '', "Zugriff Methode 2 - Reihe für Reihe")
_MySQL_Data_Seek($res, 0) ; nur zum zum Zurücksetzen an den Anfang der Abfrage
Do
$row1 = _MySQL_Fetch_Row_StringArray($res)
If @error Then ExitLoop
_ArrayDisplay($row1)
Until @error
MsgBox(0, '', "Zugriff Methode 3 - alles in ein 2D Array")
$array = _MySQL_Fetch_Result_StringArray($res)
_ArrayDisplay($array)
; Feldinformationen
MsgBox(0, '', "Zugriff Feldinformationen")
Dim $arFields[$fields][3]
For $i = 0 To $fields - 1
$field = _MySQL_Fetch_Field_Direct($res, $i)
$arFields[$i][0] = _MySQL_Field_ReadValue($field, "name")
$arFields[$i][1] = _MySQL_Field_ReadValue($field, "table")
$arFields[$i][2] = _MySQL_Field_ReadValue($field, "db")
Next
_ArrayDisplay($arFields)
; Abfrage freigeben
_MySQL_Free_Result($res)
; Verbindung beenden
_MySQL_Close($MysqlConn)
; MYSQL beenden
_MySQL_EndLibrary()