Reputation: 176
im newbie in OOP. I have file database.php
class Database{
function db_row($con,$stuff,$table,$statements){
return mysqli_fetch_array(mysqli_query($con,"SELECT {$stuff} FROM `{$table}` {$statements}"));
}}
and i have file player.php
class Player{
function get_id($con,$token){
}}
And i want to use function db_row-class Database(file database.php) in the class Player(file player.php)
How can i do this?
Upvotes: 0
Views: 164
Reputation: 23660
You could try something like this below. Basically, you instantiate the Database
object in Player
's constructor, then you can access the methods in Database
inside Player
as shown below.
<?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);
?>
Upvotes: 1