· 6 years ago · Nov 03, 2019, 08:18 PM
1<?php
2
3
4# Dati del database [Mysql]
5$db = [
6//True to activate the Database - False to disactivate it
7'status' => true,
8
9//User of database [Default: root]
10'user' => "root",
11
12//password of Database
13'password' => "",
14
15//IP of the mysql server [Default: localhost]
16'host' => "localhost",
17
18//Name of the Database
19'db_name' => ""
20];
21
22// If the Database 'status' is 'true', the database will connect with the database and creare a table
23if ($db['status']) {
24try {
25 $PDO = new PDO("mysql:host=".$db['host'].";dbname=".$db['db_name'], $db['user'], $db['password']);
26 }
27catch(PDOException $e) {
28 echo "Connection failed: " . $e->getMessage();
29 }
30
31// Create table if not exist and if the Database is [TRUE]
32 $PDO->query("CREATE TABLE IF NOT EXISTS users (
33 user_id BIGINT(20) NOT NULL,
34 first_name TEXT(50) ,
35 last_name TEXT(50),
36 username TEXT(50),
37 status VARCHAR(10) NOT NULL
38 );");
39
40//SELECT all ROW of the users table
41$fetch = $PDO->prepare("SELECT * FROM users WHERE user_id = ?");
42$fetch->execute([$HydraFW->Updater->Message->From->id]);
43$f = $fetch->fetch(\PDO::FETCH_ASSOC);
44
45// If $HydraFW->Updater->Message->From->id not exist into the Database, the script will create a row
46if ($f['user_id'] != $HydraFW->Updater->Message->From->id) {
47 if ($HydraFW->Updater->Message->Chat->type === "private") {
48 if (!$HydraFW->Updater->Message->From->last_name) {
49 $HydraFW->Updater->Message->From->last_name = "";
50 }
51 if (!$HydraFW->Updater->Message->From->username) {
52 $HydraFW->Updater->Message->From->username = "";
53 }
54 $insert = $PDO->prepare("INSERT INTO users (user_id, first_name, last_name, username, status) VALUES (?,?,?,?,?)");
55 $insert->execute([$HydraFW->Updater->Message->From->id, $HydraFW->Updater->Message->From->first_name, $HydraFW->Updater->Message->From->last_name, $HydraFW->Updater->Message->From->username, '0']);
56 }
57 }
58}
59
60?>