为了账号安全,请及时绑定邮箱和手机立即绑定

使用PDO和PHP在2个表中插入多行

使用PDO和PHP在2个表中插入多行

PHP
心有法竹 2021-04-29 13:13:13
我想在表字典中插入3行,并在表横幅中插入另外3行,因此在本示例中,我仅对每个表保留1个查询。我得到的错误是PDOStatement类的对象无法转换为字符串try {$conn = new PDO('mysql:host=mysql;dbname=mydb;charset=utf8mb4', 'root', 'tiger');$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);$conn->beginTransaction();$conn->exec("INSERT INTO `dictionary` (`id`, `it`, `en`, `fr`, `es`, `pt`, `de`, `nl`) VALUES ('1', 'Sed tempus libero a tristique placerat.\r\n', 'Curabitur at justo sit amet mi aliquam vestibulum.\r\n', 'Duis sed elit suscipit, venenatis ipsum vitae, molestie elit.\r\n', 'Ut ac tortor semper, finibus est ac, porta erat.\r\n', 'Morbi sit amet quam facilisis, tristique mi a, sagittis quam.\r\n', 'Nulla nec sem quis velit tristique tempus vel id augue.\r\n', 'Mauris tincidunt leo eget tincidunt bibendum.\r\n')");echo "New dictionary created successfully";$stmt = $conn->prepare("INSERT INTO `banner` (`id`, `dictionaryId`, `name`, `destinationURL`, `domains`, `imageURL`, `position`, `startDate`, `finishDate`) VALUES ('5', '1', 'blink', 'github.com', 'Github', :imageURL, '5', '2019-04-18 03:00:00', '2019-05-04 00:00:00')");$stmt->bindValue(':imageURL', $dropboxLink);$stmt->execute();$conn->commit();echo "New banner created successfully";} catch (PDOException $e) {echo $stmt . "<br>" . $e->getMessage();}$conn = null;
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 136 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信