如何返回我在同一查询中创建的记录。
我尝试了$row[Password]
,但它不起作用。请帮忙
$sql = "SELECT COUNT(*) FROM characters WHERE GUID=:GUID";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':GUID', $_GET['GUID'], PDO::PARAM_INT);
$stmt->bindColumn(4, $charactername);
$stmt->execute();
$res = $stmt->fetchColumn();
if($res == 1) {
echo "Already created";
}
if(!$res){
$sql = "INSERT INTO characters (GUID,Charactername,Password) VALUES (:GUID,:Charactername,FLOOR( 1000 + ( RAND( ) *8999 ) ))";
$stmt= $pdo->prepare($sql);
$stmt->bindParam(':GUID', $_GET['GUID'], PDO::PARAM_INT);
$stmt->bindParam(':Charactername', $_GET['Charactername'], PDO::PARAM_INT);
$stmt->execute();
echo " THIS password created with FLOOR";
}
答案 0 :(得分:2)
使用private void sMovieSkipSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (TotalTime.TotalSeconds > 0)
{
CurrentMediaPlayer.MediaElement.Position = TimeSpan.FromSeconds(sMovieSkipSlider.Value * TotalTime.TotalSeconds);
}
}
之后的DataContext
获取插入的记录ID,然后进行另一次查询以选择记录。
答案 1 :(得分:0)
您可以在执行后通过$id = $stmt->lastInsertId();
返回最后插入的ID,然后对返回的ID执行select。
答案 2 :(得分:0)
如果您需要获取随机生成的密码,可以使用多个查询:
// vue/types/vue.d.ts
export interface VueConstructor<V extends Vue = Vue> {
set<T>(object: object, key: string, value: T): T;
set<T>(array: T[], key: number, value: T): T;
}
如果您希望从上一个语句中插入所有值,也可以使用LAST_INSERT_ID():
<?php
$_GET['GUID'] = 1;
$_GET['Charactername'] = 'test';
$sql = "SET @password := FLOOR( 1000 + ( RAND( ) *8999 ));
INSERT INTO characters (GUID,Charactername,Password) VALUES (:GUID,:Charactername,@password);
SELECT @password as Password";
$stmt= $pdo->prepare($sql);
$stmt->bindParam(':GUID', $_GET['GUID'], PDO::PARAM_INT);
$stmt->bindParam(':Charactername', $_GET['Charactername'], PDO::PARAM_STR);
if ($stmt->execute()) {
do {
if ($rowset = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo " THIS password created with FLOOR: " . $rowset['Password'];
}
} while ($stmt->nextRowset());
}