gpt4 book ai didi

php - lastInsertId 在 PostgreSQL 中总是返回 FALSE

转载 作者:行者123 更新时间:2023-11-29 11:59:46 24 4
gpt4 key购买 nike

<分区>

我正在尝试插入一行并将其主键作为输出。但是,当我使用 lastInsertId() 时,输出总是为 False。

下面是代码片段。你能告诉我哪里错了吗?

$host        = "host=localhost";
$port = "port=5432";
$dbname = "dbname=TestDB";
$credentials = "user=Admin password=Admin";

// Connecting, selecting database
// $dbconn = pg_connect("$host $port $dbname $credentials") or die('Could not connect: ' . pg_last_error());
$conn = new PDO("pgsql:dbname=webdev;host=localhost;port=5432", 'postgres' , 'rameshnr');

// $userName = $_GET['userName'];
// $userComment = $_GET['userComment'];

$userID = 'B101';
$parentComment = 0;
$commentText = 'Test Comment';

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("INSERT INTO table_Comments(userID, parentComment, commentText) VALUES (:userID, :parentComment, :commentText)");

$stmt->bindParam(':userID', $userID, PDO::PARAM_STR, 32);
$stmt->bindParam(':parentComment', $parentComment, PDO::PARAM_INT);
$stmt->bindParam(':commentText', $commentText, PDO::PARAM_STR, 500);


$stmt->execute();

$result= $conn->lastInsertId();

echo "$result";

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com