我尝试将记录插入mysql数据库
INSERT INTO tbl_messages
(msgTitle,msgMessage,msgDateScheduled,fkmsgAppId,msgImage,msgAction,fkmsgSerial)
values
('essfd','fgf','2014-03-30T00:12','2','test.jpg','none','11111');
但是虽然声明是正确的,但我仍然收到这个错误:
查询无效:您的SQL语法出错;检查手册 对应于您的MariaDB服务器版本以获得正确的语法 使用附近' '在第1行
如果我在mysql客户端中复制并粘贴此插件,它会毫无错误地插入记录。
我无法弄清楚问题出在哪里。 任何人都可以帮助我吗?
我的代码是:
好吧,你是对的,我必须展示代码。我在Dreamweaver中完成这个项目。 实际上我读了2个数组,我创建了插入语句,我将它们插入db。
//include database file
include("dbconn.php");
//make the db connection
$myConn = new DB_Class("DB","user","password");
//initialize the string that will keep the sq
$sqlString ="";
//outer loop
foreach($arrayRecipients as $key2 => $row2){
$sqlString ="INSERT INTO tbl_messages (msgTitle,msgMessage,msgDateScheduled,fkmsgAppId,msgImage,msgAction,fkmsgSerial) values (";
//inner loop
foreach($arrayValues as $key1 => $row1){
$sqlString .= "'".$arrayValues[$key1]."',";
}//end for
//the last 3 values are fixed for now
$sqlString .= "'test.jpg','none','11111');</br>";
//i call the insert function
$myConn->insUpdRecordTest($sqlString);
//initialize sqlstirng for the next loop
$sqlString = "";
}//end for
dbconn.php上的代码是:
CLASS DB_Class {
VAR $db;
function DB_Class($dbname, $username, $password) {
$this->db = mysqli_connect ('server', $username, $password)
or DIE ("Unable to connect to Database Server");
mysqli_select_db( $this->db,$dbname) or DIE ("Could not select database");
}
function query($sql) {
$result = mysqli_query ($this->db,$sql) or DIE ("Invalid query: " . mysqli_error($this->db));
return $result;
}
///////////////////////////
function insUpdRecordTest($sql){
$result = $this->query($sql);
return $result;
}
}