本帖最后由 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 DBSET 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;
|