使用这个 php 代码:
try{
$dbh = new PDO("mysql:host=$host;dbname=$dbname",$user,$pass);
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
// INSERT CLEAN DATA INTO TABLE…
$sth = $dbh->prepare("
INSERT INTO Fan(fanNm,fanEmail,fanPass,fanDynamSalt)
VALUES('$userName','$userEmailAddress','$userPassword','$dynamSalt')"
);
$sth->execute();
////////////////////////////////////////////////////////////////////
## Set Session Var for this PK ID in Fan table that is being created ##
////////////////////////////////////////////////////////////////////
$_SESSION['newUserSessID'] = mysql_insert_id();
echo "<strong style='color:#fff;'>".$_SESSION['newUserSessID']."</strong>";
} //try
catch(PDOException $e){
echo "Oops, We're experiencing an error.";
file_put_contents('/PDODBConnectionErrors.txt', $e->getMessage(), FILE_APPEND);
} //catch
它将 FINE 插入数据库,但我echo "<strong style='color:#fff;'>".$_SESSION['newUserSessID']."</strong>";
用来回显该值,它总是返回零。
即使我运行:
SELECT LAST_INSERT_ID( )
FROM Fan
LIMIT 0 , 30
它给了我这样的输出
0
0
(因为数据库表中有两行)
任何人?