概述:我有一个应该拉基于它的ID号的数据库的排使用类方法来拉数据库信息
问题的函数:看来我的函数返回,但它没有返回任何东西。
详情:
-I这里使用2个不同的文件:db_class.php和character_pull.php
- 也我有一个包含1台(个字符)的数据库确实包含列“ ID“
- 有调试回波线。我会给出输出结果。
character_pull.php:
<?php
include "db_class.php";
echo "made it out here1";
$classobject = new db_class();
echo "made it out here2";
$results = $classobject->getPlayerStats("1");
print_r($results);
echo "made it out here3";
$id = "id: " . $results['id'];
$name = "name: " . $results['charname'];
$strength = "strength: " . $results['strength'];
$defense = "defense: " . $results['defense'];
$health = "health: " . $results['health'];
$level = "level: " . $results['level'];
$type = "type: " . $results['type'];
$experience = "experience: " . $results['experience'];
echo"<br/>";
echo "made it out here4";
?>
db_class.php:
<?php
include "database_connect.php";
class db_class{
public function getPlayerStats($id){
echo "<br/>" . "making it in class1";
$query = "SELECT * FROM characters WHERE id = $id";
$result = mysqli_query($query);
return $char = mysqli_fetch_array($result);
$result ->close();
}
}
>
当我运行该页面我收到的输出是这样的:?
做出来here1made出来here2在class1made使得它 here3做出来here4
我已经试过几件事情要解决这个问题,但我有麻烦搞清楚什么是错的。
我知道这可能是非常草率和原始的,但尽量不要笑得太难,也许你可以帮助我:P。提前致谢。
你确定在ID为“1”的字符表中有一行吗? – 2013-05-03 19:52:44
我很惊讶你不会因'包含'database_connect.php';'在类声明中出错。 – Jon 2013-05-03 19:55:43
yes表中有一行ID为1 – 2013-05-03 19:58:44