Skip to content

Commit f4881f8

Browse files
committed
finished upgraded to mysqli
1 parent bc22e59 commit f4881f8

File tree

87 files changed

+193
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+193
-187
lines changed

ActionController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function dispatchAction($action, $params = [], $tails = []) {
110110
case 'zh_hans':
111111
$pItem = 'zh_cn';
112112
}
113-
$this->locale = mysql_real_escape_string(strtolower(trim($pItem)));
113+
$this->locale = dbescape(strtolower(trim($pItem)));
114114
}
115115
break;
116116
case 'accept_timezone':
@@ -119,7 +119,7 @@ public function dispatchAction($action, $params = [], $tails = []) {
119119
&& ($pItem = $pItem[0])
120120
&& ($pItem = explode(';', $pItem))
121121
&& ($pItem = $pItem[0])) {
122-
$this->timezone = mysql_real_escape_string($pItem);
122+
$this->timezone = dbescape($pItem);
123123
}
124124
}
125125
}

DataModel.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ function stripslashes_deep($value) {
1515
function getMainDB() {
1616
global $maindb;
1717
if (!$maindb) {
18-
$maindb = mysql_connect(DBHOST, DBUSER, DBPASSWD);
19-
mysql_select_db(DBNAME, $maindb);
20-
mysql_query("SET NAMES 'utf8mb4'");
21-
# mysql_query("SET NAMES 'utf8'");
18+
$maindb = mysqli_connect(DBHOST, DBUSER, DBPASSWD, DBNAME);
19+
mysqli_query($maindb, "SET NAMES 'utf8mb4'");
2220
}
2321
}
2422
getMainDB();
@@ -35,36 +33,39 @@ public function getHelperByName($name) {
3533

3634
public function mysql_fetch_all($result) {
3735
$return = [];
38-
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
36+
while($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
3937
$return[] = stripslashes_deep($row);
4038
}
4139
return $return;
4240
}
4341

4442
public function query($sql) {
45-
mysql_query($sql);
46-
if (($error = mysql_error())) {
43+
global $maindb;
44+
mysqli_query($maindb, $sql);
45+
if (($error = mysqli_error())) {
4746
error_log("SQL error: {$error}\nSQL: {$sql}");
4847
return null;
4948
}
5049
$result = [];
51-
$insert_id = mysql_insert_id();
50+
$insert_id = mysqli_insert_id();
5251
if ($insert_id > 0) {
5352
$result['insert_id'] = strval($insert_id);
5453
}
55-
$result['affected_rows'] = mysql_affected_rows();
54+
$result['affected_rows'] = mysqli_affected_rows();
5655
return $result;
5756
}
5857

5958
public function getAll($sql) {
60-
return ($query = mysql_query($sql))
59+
global $maindb;
60+
return ($query = mysqli_query($maindb, $sql))
6161
? $this->mysql_fetch_all($query)
6262
: null;
6363
}
6464

6565
public function getRow($sql) {
66-
if($query = mysql_query($sql)) {
67-
if($return = mysql_fetch_array($query, MYSQL_ASSOC)) {
66+
global $maindb;
67+
if($query = mysqli_query($maindb, $sql)) {
68+
if($return = mysqli_fetch_array($query, MYSQL_ASSOC)) {
6869
return $return;
6970
}
7071
}
@@ -81,8 +82,9 @@ public function countNum($sql) {
8182
}
8283

8384
public function getColumn($sql) {
85+
global $maindb;
8486
$result = [];
85-
if (($query = mysql_query($sql))) {
87+
if (($query = mysqli_query($maindb, $sql))) {
8688
if($data = $this->mysql_fetch_all($query)) {
8789
foreach ($data as $row) {
8890
foreach ($row as $name => $value) {

api_controllers/v2/icsActions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function doCrosses() {
5454
$crossHelper = $this->getHelperByName('Cross');
5555
// check authorization
5656
$params = $this->params;
57-
if (!($token = mysql_real_escape_string(@$params['token']))
57+
if (!($token = dbescape(@$params['token']))
5858
|| !($rawInvitation = $modExfee->getRawInvitationByToken($token))
5959
|| $rawInvitation['state'] === 4
6060
|| !($objCross = $crossHelper->getCross($rawInvitation['cross_id']))) {

api_controllers/v2/usersActions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ public function doSetup() {
684684
apiError(400, 'weak_password', 'password must be longer than four');
685685
}
686686
// set password
687-
$name = mysql_real_escape_string(formatName($_POST['name']));
687+
$name = dbescape(formatName($_POST['name']));
688688
$stResult = $modUser->setUserPasswordAndSignin($user_id, $password, $name);
689689
if ($stResult) {
690690
// set identity name
@@ -717,7 +717,7 @@ public function doResetPassword() {
717717
if (!validatePassword($password)) {
718718
apiError(400, 'weak_password', 'password must be longer than four');
719719
}
720-
$name = mysql_real_escape_string(formatName($_POST['name']));
720+
$name = dbescape(formatName($_POST['name']));
721721
// set password
722722
$stResult = $modUser->resetPasswordByToken($token, $password, $name);
723723
if ($stResult) {

api_controllers/v3/busActions.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ class BusActions extends ActionController {
88
public function doUpdateIdentity() {
99
// get raw data
1010
$id = isset($_POST['id']) ? intval($_POST['id']) : null;
11-
$provider = isset($_POST['provider']) ? mysql_real_escape_string($_POST['provider']) : null;
12-
$external_id = isset($_POST['external_id']) ? mysql_real_escape_string($_POST['external_id']) : null;
13-
$name = isset($_POST['name']) ? mysql_real_escape_string($_POST['name']) : '';
14-
$nickname = isset($_POST['nickname']) ? mysql_real_escape_string($_POST['nickname']) : '';
15-
$bio = isset($_POST['bio']) ? mysql_real_escape_string($_POST['bio']) : '';
16-
$avatar_filename = isset($_POST['avatar_filename']) ? mysql_real_escape_string($_POST['avatar_filename']) : ''; // @todo submit by array @leask to @googollee
17-
$external_username = isset($_POST['external_username']) ? mysql_real_escape_string($_POST['external_username']) : '';
11+
$provider = isset($_POST['provider']) ? dbescape($_POST['provider']) : null;
12+
$external_id = isset($_POST['external_id']) ? dbescape($_POST['external_id']) : null;
13+
$name = isset($_POST['name']) ? dbescape($_POST['name']) : '';
14+
$nickname = isset($_POST['nickname']) ? dbescape($_POST['nickname']) : '';
15+
$bio = isset($_POST['bio']) ? dbescape($_POST['bio']) : '';
16+
$avatar_filename = isset($_POST['avatar_filename']) ? dbescape($_POST['avatar_filename']) : ''; // @todo submit by array @leask to @googollee
17+
$external_username = isset($_POST['external_username']) ? dbescape($_POST['external_username']) : '';
1818
// check data
1919
if (!$id || !$provider || !$external_id) {
2020
$this->jsonError(500, 'identity_error');
@@ -680,8 +680,8 @@ public function doRevokeIdentity() {
680680
// decode json
681681
$identity = (array) json_decode($str_args);
682682
$identity['id'] = isset($identity['id']) ? (int) $identity['id'] : 0;
683-
$identity['provider'] = isset($identity['provider']) ? mysql_real_escape_string($identity['provider']) : '';
684-
$identity['external_username'] = isset($identity['external_username']) ? mysql_real_escape_string($identity['external_username']) : '';
683+
$identity['provider'] = isset($identity['provider']) ? dbescape($identity['provider']) : '';
684+
$identity['external_username'] = isset($identity['external_username']) ? dbescape($identity['external_username']) : '';
685685
if (!$identity['id']) {
686686
if ($identity['provider'] && $identity['external_username']) {
687687
// get identity id

common.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
$exfe_res = new ResourceBundle($locale, INTL_RESOURCES);
2222
// }
2323

24+
function dbescape($string) {
25+
global $maindb;
26+
return mysqli_real_escape_string($maindb, $string);
27+
}
2428

2529
// redis by @leaskh {
2630

controllers/homeActions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public function doIndex() {
77
$modCross = $this->getModelByName('Cross');
88
$modExfee = $this->getModelByName('Exfee');
99
$modUser = $this->getModelByName('User');
10-
$token = mysql_real_escape_string($_GET['token']);
11-
$rsvp = strtolower(mysql_real_escape_string($_GET['rsvp']));
10+
$token = dbescape($_GET['token']);
11+
$rsvp = strtolower(dbescape($_GET['rsvp']));
1212
if ($token && $rsvp) {
1313
if (($objToken = $modExfee->getRawInvitationByToken($token))
1414
&& $objToken['valid']
@@ -32,7 +32,7 @@ public function doIndex() {
3232
// get sms token
3333
$this->setVar('sms_token', null);
3434
if (isset($_GET['t'])) {
35-
$t = mysql_real_escape_string($_GET['t']);
35+
$t = dbescape($_GET['t']);
3636
if (($objToken = $modUser->resolveToken($t))) {
3737
$objToken['origin_token'] = $t;
3838
}

controllers/muteActions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class MuteActions extends ActionController {
44

55
public function doCross() {
66
// get token
7-
$token = mysql_real_escape_string(trim($_GET['token']));
7+
$token = dbescape(trim($_GET['token']));
88
$modExfee = $this->getModelByName('Exfee');
99
$objToken = $modExfee->getRawInvitationByToken($token);
1010
if (!$token) {

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
error_log("+++++++ {$_SERVER['REQUEST_URI']} +++++++");
1616
if (extension_loaded('xhprof')) {
1717
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
18-
$xhprof_lib = "/usr/local/Cellar/php54-xhprof/270b75d/xhprof_lib";
18+
$xhprof_lib = "/usr/local/Cellar/php55-xhprof/254eb24/xhprof_lib";
1919
include_once "{$xhprof_lib}/utils/xhprof_lib.php";
2020
include_once "{$xhprof_lib}/utils/xhprof_runs.php";
2121
}

lib/google_api_client/io/Google_CacheParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,4 @@ public static function mustRevalidate(Google_HttpRequest $response) {
170170
// server to see if its cached entry is still usable.
171171
return self::isExpired($response);
172172
}
173-
}
173+
}

0 commit comments

Comments
 (0)