Здравствуйте, уважаемые знатоки. Не могу добиться решения данной проблемы.
[24-Nov-2019 11:38:37 Europe/Moscow] PHP Fatal error: Uncaught Error: Call to undefined function account_init() in /home/i55573/public_html/sitemysql.php:146
Stack trace:
#0 /home/i55573/public_html/site/bax_100.php(31): addUser(297991836, 'LoweBowe', '\xD0\x9B\xD0\xBE\xD1\x83')
#1 {main}
thrown in /home/i55573/public_html/site/mysql.php on line 146
<?php
function getReferal($uid)
{
$referals = 0;
$pdo = connect();
if ($pdo)
{
$stmt = $pdo->prepare('SELECT * FROM ref WHERE owner = :owner and referals <> :id');
$stmt->execute(array("owner" => $uid, "id" => $uid));
$referals = $stmt->rowCount();
}
return $referals;
}
function RefSave($uid, $refs, $first_name, $username)
{
$referals = 0;
$pdo = connect();
if ($pdo)
{
$stmt = $pdo->prepare('SELECT owner FROM ref WHERE referals = ?');
$stmt->execute([$uid]);
$referals = $stmt->rowCount();
if ($referals == 0)
{
$data = array("owner" => $refs,"referals" => $uid,
"first_name" => $first_name, "username" => $username,
"date_begin" => gmdate("d.m.Y H:i:s", time()+ ( 3 * 60 * 60 )));
$st = $pdo->prepare("INSERT INTO ref (owner, referals, first_name, username, date_begin)
VALUES(:owner, :referals, :first_name, :username, :date_begin)");
$st->execute($data);
}
$stmt = $pdo->prepare('SELECT referals FROM ref WHERE owner = ?');
$stmt->execute([$uid]);
$referals = $stmt->rowCount();
}
return $referals;
}
function getUsers($table)
{
$i = 0;
$pdo = connect();
if ($pdo)
{
$stmt = $pdo->prepare("SELECT distinct(id) FROM {$table}");
$stmt->execute();
foreach ($stmt as $row) {
$arr[$i] = $row['id'];
$i ++;
}
return $arr;
}
}
function connect()
{
$host = 'localhost';
$db = 'i55573_db'; // Имя БД
$user = 'i55573_dbuser'; // Имя пользователя БД
$pass = 'm6r1a9d63t8z9b'; // Пароль БД
$charset = 'utf8';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $user, $pass, $opt);
return $pdo;
} catch (PDOException $e) {
echo 'Подключение не удалось: ' . $e->getMessage();
return false;
// die('Подключение не удалось: ' . $e->getMessage());
}
}
function updateColumns($data,$uid)
{
$pdo = connect();
foreach ($data as $key => $value)
{
if ($value!=null && $value!="null" && $value!="")
{
$val = array(
"value" => $value,
"uid" => $uid
);
$st = $pdo->prepare("UPDATE users set {$key} = :value where id = :uid;");
$st->execute($val);
}
}
return true;
}
function MessageSave($data)
{
$pdo = connect();
if ($pdo)
{
$st = $pdo->prepare("INSERT INTO messages (user_id, username, first_name, message_id, text, date,ndate)
VALUES (:user_id, :username, :first_name, :message_id, :text, :date, :ndate)");
$st->execute($data);
return true;
}
else{ return false;}
}
function addUser($uid,$username,$first_name)
{
$pdo = connect();
if ($pdo)
{
//users
$stmt = $pdo->prepare('SELECT id FROM users WHERE id = ?');
$stmt->execute([$uid]);
if ($stmt->rowCount() == 0) // юзера нет - пишем
{
$data = array("id" => $uid,"username" => $username,"first_name" => $first_name,
"date_begin" => gmdate("d.m.Y H:i:s", time()+ ( 3 * 60 * 60 )));
$st = $pdo->prepare("INSERT INTO users (id, username, first_name,status, date_begin) VALUES(:id, :username, :first_name,0, :date_begin)");
$st->execute($data);
account_init($uid);// Инициализация баланса
}
}
}
function userget($uid)
{
$pdo = connect();
if ($pdo)
{
$stmt = $pdo->prepare('SELECT username, first_name, status FROM users WHERE id = ?');
$stmt->execute([$uid]);
$stat = [];
foreach ($stmt as $row)
{
$stat['username'] = $row['username'];
$stat['first_name'] = $row['first_name'];
$stat['status'] = $row['status'];
}
return $stat;
}
return false;
}
?>
<?php
ini_set('log_errors', 'On');
ini_set('error_log', 'php_errors.log');
include('function.php');
include('mysql.php');
include('config.php');
if (($json = valid()) == false) {exit();}
$uid = $json['message']['from']['id'];
$first_name = $json['message']['from']['first_name'];
$username = $json['message']['from']['username'];
$date = $json['message']["date"];
$msgid = $json['message']['message_id'];
$text = $json['message']['text'];
$message_array = array(
"user_id" => $uid,
"username" => $username,
"first_name" => $first_name,
"message_id" => $msgid,
"text" => $text,
"date" => $date,
"ndate" => gmdate("d.m.Y H:i:s", $date)
);
////////////// add user, save message //////////////////
MessageSave($message_array);
addUser($uid, $username, $first_name); // Добавить юзера в бд
$hello = "\n_команда не определена...попробуй _ /start ";
///////////// referal init /////////////////////////////
$ref = parseReferal($text); // извлечение ref
if ($ref) {RefSave($uid,$ref, $first_name, $username);
} // сохраняем реф
/////////////////////////////////////////////////////////
$referals = getReferal($uid);
switch ($text) {
case '/start':
$hello = "Привлеки двух юзеров и получи приватный линк";
break;
case "Получить линк":
if ($referals < 2) {
$hello =
"Чтобы получить приватный линк, необходимо, чтобы по ваше ссылке перешло *всего 2 человека*.\n
Привлечено: ".$referals."\n
Ваша реферальная ссылка:\nt.me/".$BOT_USERNAME."?start=".$uid;
}
else {$hello = 'http://google.com';}
break;
case "Рефералы":
$hello = "\nПривлечено рефералов: ".$referals;
break;
}
$keyboard = keyboard("menu");
sendMessage($uid,$hello, $keyboard);
?>
Я чайник, прошу сильно не пинаться. Что я не так сделал, помогите разобраться пожалуйста.