- ©«¤l
- 48
- ¥DÃD
- 6
- ºëµØ
- 0
- ¿n¤À
- 60
- ÂI¦W
- 0
- §@·~¨t²Î
- XP
- ³nÅ骩¥»
- Office 2003
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2012-8-13
- ³Ì«áµn¿ý
- 2023-2-7
|
¦^´_ 4# heavenweaver
¤Wºô§äÓ AutoItªºMySQL UDFs¡A´ú¸Õutf8¤Îbig5¡Aµ²ªG¬O¥Îbig5¤~¥i¥H¥¿½TÅã¥Ü¡C
´ú¸Õµ{¦¡¦p¤U¡G- #include "mysql.au3"
- #include <Array.au3>
- ;===================================================================================
- ; This is a demo script that show you how to use MySQL UDFs with AutoIT
- ; Script: MySQL UDFs working with libmysql.dll
- ; Version: 1.0.0.2
- ; Author: Prog@ndy
- ;
- ; You can dowload MySQL UDFs from this URL
- ; http://progandy.de/downloads/summary/3-autoit-udfs/4-mysql-udfs.html
- ; Remarks by : Heavenweaver Lu
- ;===================================================================================
- ; MYSQL Initiate
- _MySQL_InitLibrary()
- If @error Then Exit MsgBox(0, '', "Could not Initiate MySQL")
- Global $MysqlConn = _MySQL_Init()
- Local $res
- Database()
- ShowTableContent()
- ; Query releasing
- _MySQL_Free_Result($res)
- ; Ending a connection
- _MySQL_Close($MysqlConn)
- ; MYSQL Ending
- _MySQL_EndLibrary()
- Func DATABASE()
- Local $strHost = "127.0.0.1", $strUID = "root", $strPass = "http://forum.twbts.com", $strDB = "test"
- $connected = _MySQL_Real_Connect($MysqlConn,$strHost, $strUID ,$strPass,$strDB )
- 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)
- _MySQL_Close($MysqlConn)
- _MySQL_EndLibrary()
- Exit
- EndIf
- _MySQL_Set_Character_Set($MysqlConn, "big5")
- _MySQL_Real_Query($MysqlConn, "CREATE DATABASE IF NOT EXISTS test DEFAULT CHARSET big5")
- _MySQL_Real_Query($MysqlConn, "use test;")
- Local $timedate = "now()"
- Local $my = "00:F0:00:FF:00:FF"
- Local $Name = "testname"
- Local $IDname = "s448920"
- Local $User = "³Â»¶®a±Ú"
- Local $code = "11111"
- Local $alltest = "PASS"
- Local $time1 = "232"
- Local $time2 = "234"
- $sTable = "test"
- $strSQLcmd = "DROP TABLE IF EXISTS " & $sTable & ";"
- _MySQL_Real_Query($MysqlConn, $strSQLcmd)
- $sMySqlStatement = "CREATE TABLE IF NOT EXISTS test (" & _
- "TimeDate TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," & _
- "Name TEXT NOT NULL ," & _
- "My TEXT NOT NULL," & _
- "IDname TEXT NOT NULL ," & _
- "User TEXT NOT NULL ," & _
- "Code TEXT NOT NULL ," & _
- "Result TEXT NOT NULL ," & _
- "Time1 TEXT NOT NULL ," & _
- "Time2 TEXT NOT NULL );"
- if _MySQL_Real_Query($MysqlConn, $sMySqlStatement,StringLen($sMySqlStatement) * 2) <> $MYSQL_SUCCESS Then
- ConsoleWrite("Error: " & _MySQL_errno($MysqlConn) & " " & _MySQL_error($MysqlConn) & @LF)
- Return
- EndIf
- Local $sMySqlStatement = "INSERT INTO test (TimeDate, Name, My, IDname," & _
- "User,Code,Result,Time1,Time2) VALUES (NOW()," & _
- "'" & $my & "'," & _
- "'" & $Name & "'," & _
- "'" & $IDname & "'," & _
- "'" & $User & "'," & _
- "'" & $code & "'," & _
- "'" & $alltest & "'," & _
- "'" & $time1 & "'," & _
- "'" & $time2 & "');"
- ConsoleWrite("$sMySqlStatement " & $sMySqlStatement & @LF)
- If _MySQL_Real_Query($MysqlConn,$sMySqlStatement,StringLen($sMySqlStatement) * 2) <> $MYSQL_SUCCESS Then
- ConsoleWrite("error: " & _MySQL_errno($MysqlConn) & " " & _MySQL_error($MysqlConn) & @LF)
- MsgBox(16, "error: " & _MySQL_errno($MysqlConn), _MySQL_error($MysqlConn))
- Return
- Else
- ConsoleWrite("!mysql> Congradulation! Data Insert Compeleted" & @CRLF)
- EndIf
- EndFunc ;==>DATABASE
- Func ShowTableContent()
- $query = "SELECT * FROM test"
- _MySQL_Real_Query($MysqlConn, $query)
- $res = _MySQL_Store_Result($MysqlConn)
- $fields = _MySQL_Num_Fields($res)
- $rows = _MySQL_Num_Rows($res)
- ;MsgBox(0, "", $rows & "-" & $fields)
- ConsoleWrite("!mysql> " & "Rows = " & $rows & " x " & "Columns = " & $fields & @CRLF)
- ; Access 1
- ;MsgBox(0, '', "Access Methode 1- manual work")
- 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)
- ; Access 2
- ;MsgBox(0, '', "Access Methode 2 - Series")
- _MySQL_Data_Seek($res, 0) ; only for to the beginning of the query
- Do
- $row1 = _MySQL_Fetch_Row_StringArray($res)
- If @error Then ExitLoop
- _ArrayDisplay($row1)
- Until @error
- ;MsgBox(0, '', "Access Method 3 - all in a 2D array")
- $array = _MySQL_Fetch_Result_StringArray($res)
- _ArrayDisplay($array)
- ; Field information
- ;MsgBox(0, '', "Field information")
- 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)
- EndFunc ;==>ShowTableContent
½Æ»s¥N½X |
|