Note that there are some explanatory texts on larger screens.

plurals
  1. POCant use the class object with other class
    primarykey
    data
    text
    <p>I had 2 Class in PHP That i want to use with each other, but the Class in 2 different PHP Script like clothing_product.php and database.php. It look like this Below:</p> <p>database.php:</p> <pre><code>require_once('config.php'); class MySqlDatabase { private $connection; private $last_query; private $magic_quotes_active; private $real_escape_string_exist; function __construct(){ $this-&gt;open_connection(); $this-&gt;magic_quotes_active = get_magic_quotes_gpc(); $this-&gt;real_escape_string_exist = function_exists("mysql_real_escape_string"); } private function open_connection() { $this-&gt;connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); if (!$this-&gt;connection){ die("Connection failed!". mysql_error()); } else{ $db_select = mysql_select_db(DB_NAME); if(!$db_select){ die("Select database failed". mysql_error()); } } } public function query($sql){ $this-&gt;last_query = $sql; $result = mysql_query($sql,$this-&gt;connection); $this-&gt;confirm_query($result); return $result; } public function confirm_query($result){ if(!$result){ $output = "Database query failed: " . mysql_error()."&lt;br /&gt;&lt;br /&gt;"; $output.= "Last query that fail is:" . $this-&gt;last_query; die($output); } } private function escape_value($value) { if ($this-&gt;real_escape_string_exist) { if($this-&gt;magic_quotes_active) {$value = stripslashes($value);} $value = mysql_real_escape_string($value); } else { if (!$this-&gt;magic_quotes_active) {$value = addslashes($value);} } return $value; } public function fect_array($result){ return mysql_fetch_array($result); } public function num_rows($result){ return mysql_num_rows($result); } public function last_id(){ return mysql_insert_id($this-&gt;connection); } public function affected_rows(){ return mysql_affected_rows($this-&gt;connection); } public function close_connection(){ if(isset($this-&gt;connection)){ mysql_close($this-&gt;connection); unset($this-&gt;connection); } } } //$db = new MySqlDatabase(); </code></pre> <p>clothing_product.php:</p> <p>include('../database.php');</p> <pre><code>class Clothing_Product { public $db = new MySqlDatabase(); public static function test(){ echo "Static call successfull"; return "Static call successfull"; } } </code></pre> <p>The problem is when i try to USE 'Public $db = new MySqlDatabase();' in class clothing_product i get Error. I think the problem is maybe i got a wrong call. Please help me cuz m a noob thnk. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload