Merge branch 'ryzom/rites' into main/gingo-test
[ryzomcore.git] / ryzom / server / www / login / libs / r2_login_db.php
blob808b2cf929b46d25c90a570e1e72d1d3de891cf0
1 <?php
3 function _e($value) {
4 global $RingDb;
5 return mysqli_real_escape_string($RingDb->db, $value);
8 class LoginDB {
10 function __construct($DBHost, $DBUserName, $DBPassword, $DefaultDBName) {
11 $this->host = $DBHost;
12 $this->user = $DBUserName;
13 $this->pass = $DBPassword;
14 $this->default_name = $DefaultDBName;
15 return $this->connect();
18 function connect() {
19 $this->db = mysqli_connect($this->host, $this->user, $this->pass) or die(errorMsgBlock(3004, 'DB', $this->host, $this->user));
20 return $this->db;
23 function select($db='') {
24 if ($db)
25 $this->name = $db;
26 else
27 $this->name = $this->default_name;
28 mysqli_select_db($this->db, $this->name) or die(errorMsgBlock(3005, 'DB', $this->name, $this->host, $this->user));
31 function query($query) {
32 $result = mysqli_query($this->db, $query) or die(errorMsgBlock(3006, $query, 'DB', $this->name, $this->host, $this->user, mysqli_error($this->db)));
33 $ret = array();
34 if (!is_bool($result)) {
35 while ($row = mysqli_fetch_array($result))
36 $ret[] = $row;
38 return $ret;
41 function querySingle($query) {
42 $result = mysqli_query($this->db, $query) or die(errorMsgBlock(3006, $query, 'DB', $this->name, $this->host, $this->user, mysqli_error($this->db)));
43 if (mysqli_num_rows($result))
44 return mysqli_fetch_array($result);
45 return array();
48 function getLastId() {
49 return mysqli_insert_id($this->db);