找回密码
 加入
搜索
查看: 10597|回复: 19

[AU3基础] mysql 多行执行sql语句出错【已解决】

 火.. [复制链接]
发表于 2011-2-11 12:38:08 | 显示全部楼层 |阅读模式
本帖最后由 haodd 于 2011-2-13 10:54 编辑

au3直接运行以下sql语句报错
$sMySqlStatement = "INSERT INTO _Barinfo (ID,name,IP) VALUES ('001001','sss','100.100.100.100');INSERT INTO _Barinfo (ID,name,IP) VALUES ('001001','zzz','100.100.100.100');"
把上面语句复制到mysql是正常的
#include "mysql.au3"
#include <Array.au3> 
__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 = ""
        $connected = _MySQL_Real_Connect($MysqlConn, "localhost", "root", $Pass,"poprepchart1")
        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")
                Local $sMySqlStatement = "",$i

                While $i < 1  ;~ 当 $i 比较的数大于1时 时就会报错  添加@CR,@LF,@CRLF都会报错,不能插入记录 可是直接复制 msgbox 的内容 在mysql执行时却正常
                        $sMySqlStatement &= "INSERT INTO _info (ID,name,IP) VALUES ('001001','sss','100.100.100.100');"
                        $i += 1
                        MsgBox(0,"",$sMySqlStatement)
                WEnd
    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!")
        EndIf
EndFunc   ;==>DATABASE
---------------------------

---------这里是当while $i < 2 是的msgbox 能直接在mysql下执行插入记录---虚线不要复制 请复制sql语句---------------
INSERT INTO _info (ID,name,IP) VALUES ('001001','sss','100.100.100.100');INSERT INTO _info (ID,name,IP) VALUES ('001001','sss','100.100.100.100');
---------------------------
确定   
---------------------------
报错内容
---------------------------
error: 1064
---------------------------
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO _info (ID,name,IP) VALUES ('001001','sss','100.100' at line 1
---------------------------
确定   
---------------------------
MYSQL DB
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `_info`
-- ----------------------------
DROP TABLE IF EXISTS `_barinfo`;
CREATE TABLE `_barinfo` (
  `RecID` int(2) NOT NULL AUTO_INCREMENT,
  `ID` char(6) NOT NULL,
  `name` char(8) NOT NULL,
  `IP` char(15) NOT NULL,
  `RecordMark` int(1) DEFAULT NULL,
  `Remarks1` char(1) DEFAULT NULL,
  PRIMARY KEY (`RecID`)
) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;
发表于 2011-2-11 14:03:38 | 显示全部楼层
id是自动编号吧?
发表于 2011-2-11 14:05:19 | 显示全部楼层
好像mysql  的字符串用 ` 而不是 '
发表于 2011-2-11 14:05:58 | 显示全部楼层
头像是你本人吧?
 楼主| 发表于 2011-2-11 14:26:23 | 显示全部楼层
本帖最后由 haodd 于 2011-2-11 14:31 编辑

`RecID`  是自动编号
ID不是自动编号

把` 改成 ' 一条都插不进去了
$sMySqlStatement &= "INSERT INTO _Barinfo (ID,name,IP) VALUES (`001001`,`sss`,`100.100.100.100`);"
发表于 2011-2-11 14:37:45 | 显示全部楼层
加个回车符试试,理论上是支持多行的.可惜没条件测试.
 楼主| 发表于 2011-2-11 14:44:42 | 显示全部楼层
 While $i < 1  ;~ 当 $i 比较的数大于1时 时就会报错  添加@CR,@LF,@CRLF都会报错,不能插入记录 可是直接复制 msgbox 的内容 在mysql执行时却正常
                        $sMySqlStatement &= "INSERT INTO _info (ID,name,IP) VALUES ('001001','sss','100.100.100.100');"
                        $i += 1
                        MsgBox(0,"",$sMySqlStatement)
                WEnd
 楼主| 发表于 2011-2-11 14:46:19 | 显示全部楼层
添加过了  ,都试过了

While $i < 1  ;~ 当 $i 比较的数大于1时 时就会报错  添加@CR,@LF,@CRLF都会报错,不能插入记录 可是直接复制 msgbox 的内容 在mysql执行时却正常
                        $sMySqlStatement &= "INSERT INTO _info (ID,name,IP) VALUES ('001001','sss','100.100.100.100');"&@CR
                        $i += 1
                        MsgBox(0,"",$sMySqlStatement)
                WEnd

While $i < 1  ;~ 当 $i 比较的数大于1时 时就会报错  添加@CR,@LF,@CRLF都会报错,不能插入记录 可是直接复制 msgbox 的内容 在mysql执行时却正常
                        $sMySqlStatement &= "INSERT INTO _info (ID,name,IP) VALUES ('001001','sss','100.100.100.100');"&@CRLF
                        $i += 1
                        MsgBox(0,"",$sMySqlStatement)
                WEnd

While $i < 1  ;~ 当 $i 比较的数大于1时 时就会报错  添加@CR,@LF,@CRLF都会报错,不能插入记录 可是直接复制 msgbox 的内容 在mysql执行时却正常
                        $sMySqlStatement &= "INSERT INTO _info (ID,name,IP) VALUES ('001001','sss','100.100.100.100');"&@LF
                        $i += 1
                        MsgBox(0,"",$sMySqlStatement)
                WEnd
发表于 2011-2-11 15:31:43 | 显示全部楼层
本帖最后由 kingfirekkk 于 2011-2-11 15:45 编辑

见下贴图片所示
发表于 2011-2-11 15:44:35 | 显示全部楼层
楼主:
      表头结构修改了一下,然后直接用你的代码执行成功!图片如下:






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2011-2-11 15:56:05 | 显示全部楼层
回复 10# kingfirekkk

表头结构修改了一下????????
发表于 2011-2-11 16:01:33 | 显示全部楼层
回复  kingfirekkk

表头结构修改了一下????????
haodd 发表于 2011-2-11 15:56

对头,设为自动递增.
 楼主| 发表于 2011-2-11 16:03:19 | 显示全部楼层
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `_info`
-- ----------------------------
DROP TABLE IF EXISTS `_barinfo`;
CREATE TABLE `_barinfo` (
  `RecID` int(2) NOT NULL AUTO_INCREMENT,
  `ID` char(6) NOT NULL,
  `name` char(8) NOT NULL,
  `IP` char(15) NOT NULL,
  `RecordMark` int(1) DEFAULT NULL,
  `Remarks1` char(1) DEFAULT NULL,
  PRIMARY KEY (`RecID`)
) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;

把char 改成 text?
发表于 2011-2-11 16:04:59 | 显示全部楼层
10#的最后一张图看不明白?
发表于 2011-2-11 16:14:08 | 显示全部楼层
再发:


实际建表的语句为:

CREATE TABLE `testdata`.`_info` (
`ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`NAME` TEXT NOT NULL ,
`IP` TEXT NOT NULL
) ENGINE = MYISAM ;

这样楼主应该知道问题点在哪里了!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-2 14:37 , Processed in 0.117450 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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