-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkDB.php
More file actions
63 lines (42 loc) · 1.41 KB
/
WorkDB.php
File metadata and controls
63 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Created by PhpStorm.
* User: dell
* Date: 17.05.2019
* Time: 15:54
*/
class WorkDB
{
private $conString;
public function __construct()
{
$this->connectToDB(); //connect to database
}
private function connectToDB()
{
$config = require_once 'config.php';
$dsn = 'mysql:host='.$config['host'].';dbname='.$config['dbname'].';charset='.$config['charset'];
$this->conString= new PDO($dsn, $config['username'], $config['password']);
return $this;
}
public function AddJSONtoDB($user_name,$call_type, $number, $time, $call_time)
{
//select user_id from user list
$query = "SELECT `id` FROM `userlist` WHERE `name`=='$user_name'";
$selectquery = $this->conString->query($query);
print_r($selectquery);
$user_id = $selectquery->fetch();
// insert to table (calllist) value user_id, call_type, number, time, call_time
$callparams = [
':user_id' =>$user_id,
':call_type' => $call_type,
':number' => $number,
':time' => $time,
':call_time' =>$call_time
];
$query = "INSERT INTO `calllist` (`user_id`,`call_type`,`number`,`time`,`call_time`) VALUE (:user_id,:call_type,
:number,:time,:call_time)";
$dbo=$this->conString->prepare($query);
$dbo->execute($callparams);
}
}