-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiv2_model.php
86 lines (71 loc) · 2.58 KB
/
apiv2_model.php
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class APIv2_model extends CI_Model {
private $db = NULL;
private $drv_mssql = "mssql";
private $string_tbl = "string";
function __construct() {
parent::__construct();
// bootstrap apiv2 mssql database
$this->db = $this->load->database("default", TRUE);
}
//
public function get_daas($limit, $source) {
$this->db->select("string.*, tbl2.*");
$this->db->join("api_rdbms AS tbl2", "string.rdbms = tbl2.db_id");
$this->db->where("string.method", $source);
$query = $this->db->get($this->string_tbl);
if ($query->num_rows > 0) {
// initiate viratual varaibles from the database
$config['hostname'] = $query->row("host");
$config['username'] = $query->row("user");
$config['password'] = $query->row("passwd");
$config['database'] = $query->row("dbname");
$config['dbdriver'] = $query->row("db_driver"); // this determines the entire connection
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['char_set'] = 'utf8';
$config['dbcollat'] = 'utf8_general_ci';
$config['autoinit'] = TRUE;
$config['stricton'] = FALSE;
}
// load the virtual database
$this->apiv2 = $this->load->database($config, TRUE);
$this->apiv2->from($query->row("table"));
$this->apiv2->limit(0);
$query = $this->apiv2->get();
$connect = array();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$connect[] = $row;
}
return $connect;
}
}
//
public function dass_update($params, $source) {
$this->db->select("string.*, tbl2.*");
$this->db->join("api_rdbms AS tbl2", "string.rdbms = tbl2.db_id");
$this->db->where("string.method", $source);
$query = $this->db->get($this->string_tbl);
if ($query->num_rows > 0) {
// initiate viratual varaibles from the database
$config['hostname'] = $query->row("host");
$config['username'] = $query->row("user");
$config['password'] = $query->row("passwd");
$config['database'] = $query->row("dbname");
$config['dbdriver'] = $query->row("db_driver"); // this determines the entire connection
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['char_set'] = 'utf8';
$config['dbcollat'] = 'utf8_general_ci';
$config['autoinit'] = TRUE;
$config['stricton'] = FALSE;
}
// load the virtual database
$this->apiv2 = $this->load->database($config, TRUE);
$this->apiv2->where("user_id", "1");
return $this->apiv2->update($query->row("table"), $params);
}
}