#include "mysql.au3"#include "mysql.au3"#include__MySQL_ExtractEmbeddedDLL()_MySQL_InitLibrary()If @error Then Exit MsgBox(0, '', "could nit init MySQL")Global $MysqlConn = _MySQL_Init()Database()_MySQL_Close($MysqlConn)_MySQL_EndLibrary() Func DATABASE() $Pass = "andrew" $connected = _MySQL_Real_Connect($MysqlConn, "111.111.111.111", "root", $Pass) 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, "GBK") _MySQL_Real_Query($MysqlConn, "CREATE DATABASE IF NOT EXISTS test DEFAULT CHARSET gbk") _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 = "右地震荡" Local $code = "11111" Local $alltest = "PASS" Local $time1 = "232" Local $time2 = "234" $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 MsgBox(64, "恭喜!", "写数据到数据库OK!") EndIfEndFunc ;==>DATABASE
以上代码来自 感谢版主ceoguang.
最有价值的是 GBK,无奈UTF8不支持。
给需要找资料的朋友以帮助。