function fakePayout ($user, $amount, $time) {
$referer = 'P'.rand(4, 6).rand(1, 0).rand(000000, 999999);
$refererIncome = $amount/100*150;
$mysqli->query("INSERT INTO `deposits` (`user`, `amount`, `time`, `type`, `fake`) VALUES ('$user', '$amount', '$time', '1', '1')");
$mysqli->query("INSERT INTO `deposits` (`user`, `amount`, `time`, `type`, `fake`) VALUES ('$referer', '$refererIncome', '$time', '2', '1')");
return true;
}
class DataBase
{
public $template = 'default';
public $db_host;
public $db_user;
public $db_passord;
public $db_name;
public $mysql_port;
public $mysql_socket;
public function __construct($db_host, $db_user, $db_passord, $db_name, $mysql_port, $mysql_socket)
{
$this->db_host = $db_host;
$this->db_user = $db_user;
$this->db_passord = $db_passord;
$this->db_name = $db_name;
$this->mysql_socket = $mysql_socket;
$this->mysql_port = $mysql_port;
$mysqli = @new mysqli($this->db_host, $this->db_user, $this->db_passord, $this->db_name, $this->mysql_port, $this->mysql_socket);
if (mysqli_connect_error()) {
echo 'Подключение к серверу Mysql невозможно. Код ошибки: '.mysqli_connect_error();
exit;
}
}
}
include_once(dirname(__FILE__).'/engine/classes/Config.class.php');
$mysqli = new DataBase("localhost", "root", "", "test1488", NULL, NULL);
function fakePayout ($mysqli, $user, $amount, $time) {
function fakePayout ($mysqli, $user, $amount, $time) {
$referer = 'P'.rand(4, 6).rand(1, 0).rand(000000, 999999);
$refererIncome = $amount/100*150;
$stmt = $mysqli->prepare("INSERT INTO `deposits` (`user`, `amount`, `time`, `type`, `fake`) VALUES (?,?,?, '1', '1')");
$stmt->bind_param("sss", $user, $amount, $time);
$stmt->execute();
$stmt = $mysqli->prepare("INSERT INTO `deposits` (`user`, `amount`, `time`, `type`, `fake`) VALUES (?,?,?, '2', '1')");
$stmt->bind_param("sss", $referer, $refererIncome, $time);
$stmt->execute();
}
include_once(dirname(__FILE__).'/engine/что-нибудь/mysqli.php');
fakePayout ($mysqli,$user, $amount, $time);
$mysqli
недоступна в функции fakePayout()
. Решается одним из способов:function fakePayout($mysqli, ...) {
fakePayout()
:class SomeClass
{
private $mysqli;
public function __construct(DataBase $mysqli)
{
$this->mysqli = $mysqli;
}
public function fakePayout($user, $amount, $time)
{
// Теперь можно использовать
$this->mysqli->query()
}
}
function fakePayout ($user, $amount, $time, $mysqli) {
.....
}