php - How to restrict access to mysql connection from other classes? -



php - How to restrict access to mysql connection from other classes? -

sup! have core class mysql connection, include plugin , need plugin cant access our db without core class methods.

index.php

<?php class core { function connect() { $db = @mysql_connect($host, $user, $pass); @mysql_select_db($base, $db); } function query($sql) { homecoming mysql_query($sql); } } global $c; $c = new core(); include('plugin.php'); $p = new plugin(); echo $p->not_work_connection(); echo $p->work_connection(); ?>

plugin.php

<?php class plugin { function not_work_connection() { $sql = 'select * `net_country` limit 0 , 1'; $result = mysql_query($sql); while($row = mysql_fetch_array($result, mysql_assoc)) { homecoming print_r($row, 1); } } function work_connection() { global $c; $result =$c->query('select * `net_country` limit 0 , 1'); while($row = mysql_fetch_array($result, mysql_assoc)) { homecoming print_r($row, 1); } } } ?>

i need restrict access included scripts, thay can utilize core methods create queries. how can create it?

mysql_query without sec param uses lastly link used mysql_connect, create dummy connection after real 1 :

<?php class core { private $db; function connect() { $this->db = @mysql_connect($host, $user, $pass); @mysql_select_db($base, $db); //dummy @mysql_connect(); } function query($sql) { //notice sec param homecoming mysql_query($sql, $this->db); } } global $c; $c = new core(); include('plugin.php'); $p = new plugin(); echo $p->not_work_connection(); //doing mysql_query utilize dummy resource , fail echo $p->work_connection(); ?>

php mysql

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -