class Database{
function db_row($con,$stuff,$table,$statements){
return mysqli_fetch_array(mysqli_query($con,"SELECT {$stuff} FROM `{$table}` {$statements}"));
}}
我有文件player.php
class Player{
function get_id($con,$token){
}}
我想在类Player(文件player.php)中使用函数db_row-class Database(file database.php)
我该怎么做?
答案 0 :(得分:1)
你可以尝试下面这样的事情。基本上,您在Database
的构造函数中实例化Player
对象,然后您可以访问Database
内Player
内的方法,如下所示。
<?php
class Database{
function db_row($con,$stuff,$table,$statements){
echo "Success";
//return mysqli_fetch_array(mysqli_query($con,"SELECT {$stuff} FROM `{$table}` {$statements}"));
}}
class Player {
var $db;
function __construct() {
$this->db = new Database();
}
function get_id($con,$token){
$this->db->db_row(null, null, null, null);
}
}
$player = new Player();
$player->get_id(null, null);
?>