|
@@ -31,7 +31,9 @@ class Install
|
31
|
31
|
false;
|
32
|
32
|
}
|
33
|
33
|
|
34
|
|
- $this->create_db();
|
|
34
|
+ if (!$this->create_db()) {
|
|
35
|
+ return false;
|
|
36
|
+ }
|
35
|
37
|
|
36
|
38
|
if (!$this->install_db()) {
|
37
|
39
|
return false;
|
|
@@ -47,7 +49,13 @@ class Install
|
47
|
49
|
$db_login = $this->data['db_login'];
|
48
|
50
|
$db_password = $this->data['db_password'];
|
49
|
51
|
|
50
|
|
- $link = new PDO("mysql:host=$db_host;dbname=$db_name", $db_login, $db_password);
|
|
52
|
+ try {
|
|
53
|
+ $link = new PDO("mysql:host=$db_host;dbname=$db_name", $db_login, $db_password);
|
|
54
|
+ }
|
|
55
|
+ catch (Exception $e)
|
|
56
|
+ {
|
|
57
|
+ return false;
|
|
58
|
+ }
|
51
|
59
|
|
52
|
60
|
if (!$link) {
|
53
|
61
|
die('Could not connect: ' . $link->errorInfo());
|
|
@@ -64,8 +72,7 @@ class Install
|
64
|
72
|
|
65
|
73
|
public function install_db()
|
66
|
74
|
{
|
67
|
|
- require_once(Absolute_Path.'config.php');
|
68
|
|
- $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
|
|
75
|
+ $db = new Conexion_Mysql($this->data['db_name'], $this->data['db_host'], $this->data['db_login'], $this->data['db_password']);
|
69
|
76
|
$sqlStr = array();
|
70
|
77
|
|
71
|
78
|
$sqlStr[] = "CREATE TABLE `".Table_prefix."data` ( `id_post` INT(11) NOT NULL AUTO_INCREMENT , `title` TEXT NULL , `url` VARCHAR(250) NULL DEFAULT NULL , `description` TEXT NULL , `type` TINYINT(4) NOT NULL DEFAULT '1' , `date` DATETIME NOT NULL , `id_user` INT(10) NOT NULL , PRIMARY KEY (`id_post`)) ENGINE = MyISAM;";
|
|
@@ -99,6 +106,11 @@ class Install
|
99
|
106
|
}
|
100
|
107
|
}
|
101
|
108
|
|
|
109
|
+ if($this->writeConfig($this->data['db_name'], $this->data['db_host'], $this->data['db_login'], $this->data['db_password']) === FALSE)
|
|
110
|
+ {
|
|
111
|
+ return false;
|
|
112
|
+ }
|
|
113
|
+
|
102
|
114
|
return true;
|
103
|
115
|
}
|
104
|
116
|
|
|
@@ -110,6 +122,12 @@ class Install
|
110
|
122
|
return true;
|
111
|
123
|
}
|
112
|
124
|
|
|
125
|
+ public function writeConfig($name, $host, $login, $password)
|
|
126
|
+ {
|
|
127
|
+ $strToWrite = "define('DB_Server', '$host');\ndefine('DB_name', '$name');\ndefine('DB_User', '$login');\ndefine('DB_Password', '$password');\n";
|
|
128
|
+ return file_put_contents(Absolute_Path.'config.php', $strToWrite, FILE_APPEND | LOCK_EX);
|
|
129
|
+ }
|
|
130
|
+
|
113
|
131
|
public function mostrarerror($n)
|
114
|
132
|
{
|
115
|
133
|
if ($this->inerrors($n)) {
|