-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
funcs.php
58 lines (48 loc) · 1.57 KB
/
funcs.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
<?php
namespace funcs;
class Functions
{
public static function conn() {
/* MySQL VARIABLES */
$db_serv = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "kat_db";
return mysqli_connect($db_serv, $db_user, $db_pass, $db_name);
}
/**
* @param boolean $db_conn
* @param string $sql
*/
public static function query($db_conn, $sql) {
return mysqli_query($db_conn, $sql);
}
public static function changeDbDetails($mysql_host = "localhost", $mysql_username = "root", $mysql_password = "", $mysql_dbname = "kat_db") {
// Open funcs.php file for editing
$fname = "funcs.php";
$content = file_get_contents($fname);
// Replace with new details
$content = preg_replace(
[
'/\$db_serv = "(.*)"/',
'/\$db_user = "(.*)"/',
'/\$db_pass = "(.*)"/',
'/\$db_name = "(.*)"/'
],
[
'$db_serv = "'.$mysql_host.'"',
'$db_user = "'.$mysql_username.'"',
'$db_pass = "'.$mysql_password.'"',
'$db_name = "'.$mysql_dbname.'"'
],
$content,
1
);
// Write to funcs.php
if (file_put_contents($fname, $content)) {
return true;
}
return false;
}
}
?>