Sup! We have core class with mysql connection, than we include plugin and we need that plugin cant access to 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)
{
return 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 * FROM `net_country` LIMIT 0 , 1';
$result = mysql_query($sql);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
return print_r($row, 1);
}
}
function work_connection()
{
global $c;
$result =$c->query('SELECT * FROM `net_country` LIMIT 0 , 1');
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
return print_r($row, 1);
}
}
}
?>
I need restrict access from included scripts, but thay can use core methods to make queries. How i can make it?
mysql_query without the second param uses the last link used by mysql_connect, so you could create a dummy connection after the real one :