mysql错误但在mysql工作台上运行正常
MySQL Query works fine using MySQL workbench but produces an error when I am executing it through PHP.
$sql = "INSERT INTO authors (submission_id, first_name, last_name, email, affiliation, country)
VALUES ('83', 'Chris', 'Hobbit', 'asfasf@gmail.com','Maryland', 'PK');
UPDATE articles
SET title='83',
abstract = 'Comp'
where article_id = '83';
";
$result = Model::getConnection()->query($sql) or die(mysqli_error(Model::getConnection()));
This is the error I get from PHP.
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 'UPDATE articles SET title='83', abstract = 'Comp' where article_id = '8' at line 1
Yet this same SQL script works fine on MySQL workbench. Whats the problem?
MySQL Query使用MySQL工作台正常工作但在我通过PHP执行时会产生错误。 p> \ n
$ sql =“INSERT INTO authors(submission_id,first_name,last_name,email,affiliation,country)
VALUES('83','Chris','Hobbit','asfasf @ gmail.com ','马里兰','PK');
UPDATE文章
SET title = '83',
abstract ='Comp'
where article_id = '83';
“;
$ result = Model :: getConnection() - > query($ sql)或die(mysqli_error(Model :: getConnection()));
code> pre>
这是我从PHP得到的错误。 p>
您的SQL语法中有错误; 检查
对应于您的MySQL服务器版本的手册,以获得正确的语法,使用
“UPDATE articles SET title ='''',abstract ='Comp',其中
article_id ='8'在第1行 p >
blockquote>
然而,这个相同的SQL脚本在MySQL工作台上运行良好。 问题是什么? p>
div>
You cannot execute multiple queries with mysql_query
. Split your query into two (and get rid of the semicolons I think) and call mysql_query
twice
Put your sql statement on two variables
$query = "INSERT INTO authors (submission_id, first_name, last_name, email, affiliation, country)
VALUES ('83', 'Chris', 'Hobbit', 'asfasf@gmail.com','Maryland', 'PK')";
$query1 = "UPDATE articles SET title='83', abstract = 'Comp' where article_id = '83'";
Then execute your queries:
$result = Model::getConnection()->query($query) or die(mysqli_error(Model::getConnection()));
$result = Model::getConnection()->query($query1) or die(mysqli_error(Model::getConnection()));