首页 > 解决方案 > php页面使用PDO写入mysql的问题

问题描述

如果我直接在 phpmyadmin 中将以下命令作为 SQL 运行,则以下命令有效

CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM De_Lijst WHERE Nieuw = "Ja";
UPDATE tmptable_1 SET DB_ID = NULL, Nieuw = "", Positie =0, Datum_Af = CURRENT_DATE;
INSERT INTO De_Lijst SELECT * FROM tmptable_1;
DROP TEMPORARY TABLE IF EXISTS tmptable_1;
update De_Lijst set Info =if(Nieuw ="Ja","",Info);
update De_Lijst set Datum_Af =if(Nieuw ="Ja","",Datum_Af);
update De_Lijst set Datum_Op =if(Nieuw ="Ja","",Datum_Op);
update De_Lijst set Titel =if(Nieuw ="Ja","",Titel);
update De_Lijst set Artiest =if(Nieuw ="Ja","",Artiest);
update De_Lijst set Nieuw =if(Nieuw ="Ja","",Nieuw);
update De_Lijst set Nieuw =if(Nieuw ="Nieuw","",Nieuw);

我创建了一个名为 reset.php 的页面,看起来像这样

<?php

require 'database.php';
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = 'update De_Lijst set Info =if(Nieuw ="Ja","nee",Info)';
$q = $pdo->prepare($sql);

$q->execute(array($Nieuw,$Positie,$Artiest,$Titel,$Info,$Datum_Op,$Datum_Af)); 数据库::disconnect();

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
    <link rel="stylesheet" href="./bootstrap-4.0.0/dist   /css/bootstrap.min.css">
    <link rel="stylesheet" href="./css/custom.css">
    <script src="./bootstrap-4.0.0/dist/js/bootstrap.bundle.min.js">     </script>
</head>
<body>
 Hello<br>

<form method="POST" action="reset.php">
    <input type="submit" name="reset" value="reset"/>
</form>

</body>
</html>

php 文件只是一个查询的测试,但我需要所有的 sql 插入。但会导致 500 错误。关于我做错了什么的任何信息?

谢谢, 雅克

标签: phpmysqlpdo

解决方案


推荐阅读