Php 插入不工作,但选择查找同一页上的数据
我使用PDO(php/mysql)将一个简单条目插入到数据库表中。连接设置正确,数据似乎已插入。稍后在同一页上(插入之后),我调用一个select语句来获取该表中的所有数据。它返回所有内容,包括新插入的列(及其递增的id) 但是当我刷新站点时——或者只是在phpmyadmin中查看一下表——新条目就不见了。。。目前还没有删除代码 这是插入的代码Php 插入不工作,但选择查找同一页上的数据,php,mysql,pdo,Php,Mysql,Pdo,我使用PDO(php/mysql)将一个简单条目插入到数据库表中。连接设置正确,数据似乎已插入。稍后在同一页上(插入之后),我调用一个select语句来获取该表中的所有数据。它返回所有内容,包括新插入的列(及其递增的id) 但是当我刷新站点时——或者只是在phpmyadmin中查看一下表——新条目就不见了。。。目前还没有删除代码 这是插入的代码 // prep statement $stmt = $pdo->prepare("INSERT INTO garage (created_a
// prep statement
$stmt = $pdo->prepare("INSERT INTO garage (created_at, created_by, modified_at, modified_by, caption, description, picture) VALUES (:created_at, :created_by, :modified_at, :modified_by, :caption, :description, :picture);");
// binding params, all rows return true
$stmt->bindParam(":created_at", $ts, PDO::PARAM_STR);
$stmt->bindParam(":created_by", $user_id, PDO::PARAM_INT);
$stmt->bindParam(":modified_at", $ts, PDO::PARAM_STR);
$stmt->bindParam(":modified_by", $user_id, PDO::PARAM_INT);
$stmt->bindParam(":caption", $caption, PDO::PARAM_STR);
$stmt->bindParam(":description", $description, PDO::PARAM_STR);
$stmt->bindParam(":picture", $filename, PDO::PARAM_STR);
$stmt->execute(); // returns true
下面是几行代码:
$selStmt = $pdo->prepare("SELECT id, caption, description, picture FROM garage;");
$selStmt->execute();
while ($row = $selStmt->fetchObject()) {
echo $row->id; // output is working, id is next increment
}
有什么建议吗?提前谢谢 你在使用交易吗?啊,是的。没有想到谢谢。谢谢哈哈,那就是问题所在吗?只是忘记了$pdo->commit();