mysql_query sk_success,如何对SQL执行多个查询

I am trying to create a table and , insert some values in database with help of PHP script.

While inserting only 1 row , it works fine. An when I try to enter more number of rows , It gives error;

I need to write whole insert statement for every query as I am using an online excel to SQL query converter.

error_reporting(E_ALL);

ini_set('display_errors', '1');

include_once("connect_to_Mysql.php");

$sqlCommand = "CREATE TABLE book (

Book_Index INT,

Book_name VARCHAR(38) CHARACTER SET utf8,

author_name VARCHAR(5) CHARACTER SET utf8,

Publisher VARCHAR(5) CHARACTER SET utf8,

Category INT,

Subcategory VARCHAR(21) CHARACTER SET utf8,

Price INT)";

$query = mysqli_query($db_conx,$sqlCommand) or die(mysqli_error($db_conx));

echo "

Success creating book table

";

$sqlCommand = "

INSERT INTO book VALUES (1,'Concepts of Physics Volume I','hc verma','bharti bhavan','jee','physics',635,'english');

INSERT INTO book VALUES (2,'PLANE TRIGONOMETRY Part-1','sl loni','arihant publication','jee','math',95,'english');

INSERT INTO book VALUES (3,'VIT (VELLORE) EDGE SOLVED PAPERS & 10 MOCK TESTS (2007-2015)','Arihant Experts','arihant publication','vit','all in one',345,'english');

INSERT INTO book VALUES (4,'A Textbook of Algebra','sk goyal','arihant publication','jee','math',425,'english');

INSERT INTO book VALUES (5,'New Pattern IIT JEE PHYSICS','dc pandey','arihant publication','jee','physics',665,'english');

INSERT INTO book VALUES (6,'Objective Approach to Mathematics','amit m aggrawal','arihant publication','jee','math',710,'english');

INSERT INTO book VALUES (7,'A Complete Success Package for','Experts Compilation','arihant publication','bitsat','all in one',775,'english');

INSERT INTO book VALUES (8,'15 Years'' Solved Papers for AMU Engineering Entrance Exam','arihant Experts','arihant publication','AMU','all in one',325,'english');

INSERT INTO book VALUES (9,'Solved Papers & 5 Mock Tests for BVP Engineering','arihant Experts','arihant publication','BVP','all in one',365,'english');

";

$query = mysqli_query($db_conx,$sqlCommand) or die(mysqli_error($db_conx));

echo "

Success populating the pages table with data

";

?>

OUTPUT

Successful database connection, happy coding!!!

Success creating book table

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 book VALUES (2,'PLANE TRIGONOMETRY Part-1','sl loni','arihant public' at line 2

解决方案

Use mysqli_multi_query instead of mysqli_query, that should do it.

$query = mysqli_multi_query($db_conx,$sqlCommand) or die(mysqli_error($db_conx));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值