测试网站:csgodice.co.uk
我一直在调查PDO,但它让我困惑,我只有14而且我不是关于php中的mysql的知识我所知道的是使用PDO和数据库的某些部分,我想知道我将如何插入一个可更改的值,例如余额,这是我想要作为行插入到表中的信息
$conn->prepare("INSERT INTO users (64ID, BALANCE, AMOUNTBET) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $64id, $balance, $amountbet );
// set parameters and execute
$_64id = "$steamprofile['steamid']";
$balance = "";
$amountbet = "";
$stmt->execute();
我已经连接到我的mysql所以这一切都已完成,我真正需要知道的是如何插入行?我知道有关于它的文档,但那里的主题与我想要做的不同?
答案 0 :(得分:0)
从PHP文档http://php.net/manual/en/pdostatement.bindparam.php
获取<?php
/* Execute a prepared statement by binding PHP variables */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour');
$sth->bindParam(':calories', $calories, PDO::PARAM_INT);
$sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12);
$sth->execute();
?>
所以你的代码将是:
$stmt = $conn->prepare("INSERT INTO users (64ID, BALANCE, AMOUNTBET) VALUES (:_64id, :balance, :amountbet)");
$_64id = $steamprofile['steamid'];
$balance = "";
$amountbet = "";
$stmt->bind_param(:_64id, $_64id);
$stmt->bind_param(:balance, $balance);
$stmt->bind_param(:amountbet, $amountbet);
$stmt->execute();