我试着不要感到沮丧,但我最近才知道mysql_ *在PHP中被折旧了.我已经决定学习如何使用PDO.我今天下午刚看到它,并且使用它连接到数据库很简单,但后来我想用它取一行并将行保存为由列名索引的数组(与函数相同的方式) mysql_fetch_array确实).我无法弄清楚是为了挽救我的生命.我将发布我的代码以澄清,我确信它是简单的(所有编程错误总是很简单)但我肯定做错了.
//CONNECT TO DATABASE
$host = $_PARAM["DatabaseServer"];
$db = $_PARAM["MainDatabase"];
$dbuser = $_PARAM["DatabaseUser"];
$dbpass = $_PARAM["DatabasePass"];
try
{
$Database = new PDO("mysql:host=$host;dbname=$db", $dbuser, $dbpass);
}
catch (PDOException $e)
{
echo "There was an unexpected error. Please try again, or contact us with concerns";
}
$stmt = $Database->prepare("SELECT * FROM users WHERE username=?");
$stmt->execute(array($sUserCook));
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo $row["username"];
感谢您的帮助.
亚历克斯