php - How to use function in one class in another -
im newbie in oop. have file database.php
class database{ function db_row($con,$stuff,$table,$statements){ return mysqli_fetch_array(mysqli_query($con,"select {$stuff} `{$table}` {$statements}")); }}
and have file player.php
class player{ function get_id($con,$token){ }}
and want use function db_row-class database(file database.php) in class player(file player.php)
how can this?
you try below. basically, instantiate database
object in player
's constructor, can access methods in database
inside player
shown below.
<?php class database{ function db_row($con,$stuff,$table,$statements){ echo "success"; //return mysqli_fetch_array(mysqli_query($con,"select {$stuff} `{$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); ?>
Comments
Post a Comment