我有一个数据库,该数据库用于为我在Xcode中工作的应用程序创建数组。我下面的教程我在互联网上找到这里,我跟着指示,但我的页显示的是一个内部服务器错误。我假设我没有正确更改以下代码中的信息。另外,我的Web主机使用的是MYSQL而不是MYSQLite,因此我不确定在代码中将“ new mysqli”更改为什么。由于明显的原因,我省略了数据库信息。该数据库具有一个名为“描述”的表,并且这些列标记为1-50,并分配了不同的值。
<?php
class RedeemAPI {
private $db;
// Constructor - open DB connection
function __construct() {
$this->db = new mysqli('hostname', 'Username', 'Pass', 'Database Name');
$this->db->autocommit(FALSE);
}
// Destructor - close DB connection
function __destruct() {
$this->db->close();
}
// Main method to redeem a code
function redeem() {
// Print all codes in database
$stmt = $this->db->prepare('SELECT 1 FROM descriptions');
$stmt->execute();
$stmt->bind_result($1);
while ($stmt->fetch()) {
echo "$1";
}
$stmt->close();
}
}
// This is the first thing that gets called when this page is loaded
// Creates a new instance of the RedeemAPI class and calls the redeem method
$api = new RedeemAPI;
$api->redeem();
?>
PHP变量必须以字母或开头_
,因此您的错误源于以下语句:
$stmt->bind_result($1);
将变量名称更改为类似$ col1的名称,或任何有意义的名称。
同样,您的select
语句将返回一个值:1.您可能打算这样做:
SELECT * FROM descriptions
另外两点:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句