Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.26 KB | None | 0 0
  1. include(class_dbmanager.php)
  2. $this->DBMANAGER = new Class_DbManager();
  3. $Query['DatabaseName'] = "SELECT user FROM table_user WHERE unsername='" . $username . "';";
  4. $BDResult = $this->DBMANAGER->GetData($Query);
  5.  
  6. $Query['DatabaseName'][] = "INSERT INTO Tbl_Sys_Usuarios(IdTUser, Username, Password, Email) VALUES ('$IdTUser', '$Username', '$Password', '$Email');";
  7. $BDResult = $this->DBMANAGER->InsertData($Query);
  8.  
  9. <?php
  10. class Class_DbManager {
  11. //for select
  12. //$Query is array with database index and query string
  13. //$Conf is secundary conection data
  14. public function GetData($Query, $Conf = '') {
  15. try {
  16. $DB_R = [];
  17. $DB = [];
  18. $val = [];
  19. $prefix = '';
  20. $count = 0;
  21. if (USEPREFIX == True) {
  22. $prefix = DB_PRE; //prefix DB
  23. }
  24. reset($Query);
  25. $DB_2USE = key($Query);
  26. //Conecction. i use defined const...
  27. $conn = new PDO("mysql:host=" . DB_HOST . ";dbname=" . $prefix . "" . DBSYS . "", DB_USER, DB_PASS);
  28. //secundary Connection
  29. if (isset($Conf['CONF']['ChangeServ'])) {
  30. if ($Conf['CONF']['ChangeServ'] == true) {
  31. $conn = new PDO("mysql:host=" . $Conf['CONF']['DB_HOST'] . ";dbname=" . $Conf['CONF']['PREFIX2USE'] . "" . $Conf['CONF']['DB2USE'] . "", $Query['CONF']['DB_USER'], $Query['CONF']['DB_PASS']);
  32. }
  33. }
  34. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  35. $conn->exec("set names utf8");
  36. $conn->exec('USE ' . $DB_2USE);
  37. //execution query.
  38. $DB_R['r'] = $conn->query($Query[$DB_2USE], PDO::FETCH_ASSOC);
  39. $count = $DB_R['r']->rowCount();
  40. $DB_R['c'] = $count;
  41. if ($count == 0) {
  42. $DB_R['r'] = null;
  43. } elseif ($count == 1) {
  44. $DB_R['r'] = $DB_R['r']->fetch(); //Fetch result i f result is 1 if not resturn the result unfetch
  45. }
  46. $conn = null;
  47. return $DB_R;
  48. } catch (PDOException $e) {
  49. echo '<pre>';
  50. echo var_dump($e);
  51. echo '<pre>';
  52. }
  53. }
  54. //for Update and Insert
  55. //$Query is array with database index and query string
  56. //$Conf is secundary conection data
  57. public function UpdateData($Query, $Conf = '') {
  58. try {
  59. $DB_R = [];
  60. $DB = [];
  61. $val = [];
  62. $prefix = '';
  63. $cT = 0;
  64. if (USEPREFIX == True) {
  65. $prefix = DB_PRE;
  66. }
  67. $conn = new PDO("mysql:host=" . DB_HOST . ";dbname=" . $prefix . "" . DBSYS . "", DB_USER, DB_PASS);
  68. if (isset($Conf['CONF']['ChangeServ'])) {
  69. if ($Conf['CONF']['ChangeServ'] == true) {
  70. $conn = new PDO("mysql:host=" . $Conf['CONF']['DB_HOST'] . ";dbname=" . $Conf['CONF']['PREFIX2USE'] . "" . $Conf['CONF']['DB2USE'] . "", $Query['CONF']['DB_USER'], $Query['CONF']['DB_PASS']);
  71. }
  72. }
  73. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  74. $conn->beginTransaction();
  75. $conn->exec("set names utf8");
  76. foreach ($Query as $DB_2USE => $QArr) {
  77. $conn->exec('USE ' . $DB_2USE);
  78. foreach ($QArr as $key => $QString) {
  79. $conn->exec($QString);
  80. $cT++;
  81. }
  82. }
  83. $conn->commit();
  84. $conn = null;
  85. $DB_R['r'] = true;
  86. return $DB_R;
  87. } catch (PDOException $e) {
  88. #rollback al autoincrement
  89. $conn->rollback();
  90. $conn->beginTransaction();
  91. $conn->exec("set names utf8");
  92. foreach ($Query as $DB_2USE => $QArr) {
  93. $conn->exec('USE ' . $DB_2USE);
  94. foreach ($QArr as $key => $QString) {
  95. preg_match('/bintobs*(w+)/i', $QString, $tables);
  96. $conn->exec("ALTER TABLE " . $tables[1] . " AUTO_INCREMENT=1;");
  97. }
  98. }
  99. $conn->commit();
  100. echo '<pre>';
  101. echo var_dump($e);
  102. echo '<pre>';
  103. }
  104. }
  105. //for Insert
  106. //$Query is array with database index and query string
  107. //$Conf is secundary conection data
  108. public function InsertData($Query, $Conf = '') {
  109. try {
  110. $DB_R = [];
  111. $DB = [];
  112. $val = [];
  113. $prefix = '';
  114. $cT = 0;
  115. if (USEPREFIX == True) {
  116. $prefix = DB_PRE;
  117. }
  118. $conn = new PDO("mysql:host=" . DB_HOST . ";dbname=" . $prefix . "" . DBSYS . "", DB_USER, DB_PASS);
  119. if (isset($Conf['CONF']['ChangeServ'])) {
  120. if ($Conf['CONF']['ChangeServ'] == true) {
  121. $conn = new PDO("mysql:host=" . $Conf['CONF']['DB_HOST'] . ";dbname=" . $Conf['CONF']['PREFIX2USE'] . "" . $Conf['CONF']['DB2USE'] . "", $Query['CONF']['DB_USER'], $Query['CONF']['DB_PASS']);
  122. }
  123. }
  124. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  125. $conn->beginTransaction();
  126. $conn->exec("set names utf8");
  127. foreach ($Query as $DB_2USE => $QArr) {
  128. $conn->exec('USE ' . $DB_2USE);
  129. foreach ($QArr as $key => $QString) {
  130. $conn->exec($QString);
  131. $cT++;
  132. }
  133. }
  134. $conn->commit();
  135. $conn = null;
  136. $DB_R['r'] = true;
  137. return $DB_R;
  138. } catch (PDOException $e) {
  139. #rollback al autoincrement
  140. $conn->rollback();
  141. $conn->beginTransaction();
  142. $conn->exec("set names utf8");
  143. foreach ($Query as $DB_2USE => $QArr) {
  144. $conn->exec('USE ' . $DB_2USE);
  145. foreach ($QArr as $key => $QString) {
  146. preg_match('/bintobs*(w+)/i', $QString, $tables);
  147. $conn->exec("ALTER TABLE " . $tables[1] . " AUTO_INCREMENT=1;");
  148. }
  149. }
  150. $conn->commit();
  151. echo '<pre>';
  152. echo var_dump($e);
  153. echo '<pre>';
  154. }
  155. }
  156. //for delete
  157. //$Query is array with database index and query string
  158. //$Conf is secundary conection data
  159. public function DeleteData($Query, $Conf = '') {
  160. try {
  161. $DB_R = [];
  162. $DB = [];
  163. $val = [];
  164. $prefix = '';
  165. $cT = 0;
  166. if (USEPREFIX == True) {
  167. $prefix = DB_PRE;
  168. }
  169. $conn = new PDO("mysql:host=" . DB_HOST . ";dbname=" . $prefix . "" . DBSYS . "", DB_USER, DB_PASS);
  170. if (isset($Conf['CONF']['ChangeServ'])) {
  171. if ($Conf['CONF']['ChangeServ'] == true) {
  172. $conn = new PDO("mysql:host=" . $Conf['CONF']['DB_HOST'] . ";dbname=" . $Conf['CONF']['PREFIX2USE'] . "" . $Conf['CONF']['DB2USE'] . "", $Query['CONF']['DB_USER'], $Query['CONF']['DB_PASS']);
  173. }
  174. }
  175. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  176. $conn->beginTransaction();
  177. $conn->exec("set names utf8");
  178. foreach ($Query as $DB_2USE => $QArr) {
  179. $conn->exec('USE ' . $DB_2USE);
  180. foreach ($QArr as $key => $QString) {
  181. $conn->exec($QString);
  182. $cT++;
  183. }
  184. }
  185. $conn->commit();
  186. $conn = null;
  187. $DB_R['r'] = true;
  188. return $DB_R;
  189. } catch (PDOException $e) {
  190. #rollback al autoincrement
  191. $conn->rollback();
  192. $conn->beginTransaction();
  193. $conn->exec("set names utf8");
  194. foreach ($Query as $DB_2USE => $QArr) {
  195. $conn->exec('USE ' . $DB_2USE);
  196. foreach ($QArr as $key => $QString) {
  197. preg_match('/bintobs*(w+)/i', $QString, $tables);
  198. $conn->exec("ALTER TABLE " . $tables[1] . " AUTO_INCREMENT=1;");
  199. }
  200. }
  201. $conn->commit();
  202. echo '<pre>';
  203. echo var_dump($e);
  204. echo '<pre>';
  205. }
  206. }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement