找回密码
 加入
搜索
查看: 3338|回复: 0

[AU3基础] mysql操作

[复制链接]
发表于 2010-4-2 13:34:10 | 显示全部楼层 |阅读模式
本帖最后由 liangxm 于 2010-4-2 13:42 编辑

用mysql的例子想测试测试数据库操作,遇到以下的报错:

D:\autoit3\Examples\MySQL\1.au3 (52) : ==> ????????.:
Dim $array[$rows][$fields]
Dim $array[^ ERROR
Error in my_thread_global_end(): 1 threads didn't exit


$rows值是4294967296
$fields值是9
我想是不是由于$rows值太大所以才会报“Dim $array[$rows][$fields]”定义错误,但我修改了查询语句,只查出1条,但$rows值还是很大,然后还是报错,不知道是怎么回事?

用命令查询的结果是:

mysql> select * from loginlogout_log where timestamp like '2010-04-02 11:27:32'
order by user_name;
+--------+-----------+------------+-------------------+----------------+--------
--+---------------+---------------------+---------+
| id     | user_name | ip         | mac               | log_time       | log_typ
e | computer_name | timestamp           | version |
+--------+-----------+------------+-------------------+----------------+--------
--+---------------+---------------------+---------+
| 173760 | yangx     | 10.2.19.19 | 00:1A:92:63:8D:55 | 20100402112732 |
0 | PCW0060       | 2010-04-02 11:27:32 |       0 |
+--------+-----------+------------+-------------------+----------------+--------
--+---------------+---------------------+---------+
1 row in set (0.06 sec)



代码如下:

#include <array.au3>
#include "mysql.au3"

; MYSQL starten, DLL im PATH (enth鋖t auch @ScriptDir), sont Pfad zur DLL angeben. DLL muss libmysql.dll hei遝n.
_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,"localhost","root","123456","mysql",3306,"","0")

#cs ----------------------------------------------------------------------------
;MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag)
#ce ----------------------------------------------------------------------------

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","123456","test",3306,"","0")


If $connected = 0 Then Exit MsgBox(16, 'Connection Error', _MySQL_Error($MysqlConn))

$query = "select * from loginlogout_log where timestamp like '2010-04-02 11:27:32' order by user_name;"


_MySQL_Real_Query($MysqlConn, $query)


$res = _MySQL_Store_Result($MysqlConn)

$fields = _MySQL_Num_Fields($res)


$rows = _MySQL_Num_Rows($res)

MsgBox(0, "", "$rows= "& $rows & "-" & "$fields= "& $fields)

; Zugriff 1
;MsgBox(0, '', "Zugriff Methode 1- Handarbeit")

MsgBox(0, '1', $res)


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)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-16 17:58 , Processed in 0.074932 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表