Guest User

Untitled

a guest
Jan 15th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. <?PHP
  2.  
  3. //in my header file that is included on every page I have this
  4. $DB["dbName"] = "emails";
  5. $DB["host"] = "localhost";
  6. $DB["user"] = "root";
  7. $DB["pass"] = "";
  8. $link = mysql_connect($DB['host'], $DB['user'], $DB['pass']) or die("<center>An Internal Error has Occured. Please report following error to the webmaster.<br><br>".mysql_error()."'</center>");
  9. mysql_select_db($DB['dbName']);
  10. // end header connection part
  11.  
  12. // function from a functions file that I run a mysql query through in any page.
  13. function executeQuery($sql) {
  14. $result = mysql_query($sql);
  15. if (mysql_error()) {
  16. $error = '<BR><center><font size="+1" face="arial" color="red">An Internal Error has Occured.<BR> The error has been recorded for review</font></center><br>';
  17. if ($_SESSION['auto_id'] == 1) {
  18. $sql_formatted = highlight_string(stripslashes($sql), true);
  19. $error .= '<b>The MySQL Syntax Used</b><br>' . $sql_formatted . '<br><br><b>The MySQL Error Returned</b><br>' . mysql_error();
  20. }
  21. die($error);
  22. }
  23. return $result;
  24. }
  25.  
  26. // example query ran on anypage of the site using executeQuery function
  27. $sql='SELECT auto_id FROM friend_reg_user WHERE auto_id=' .$info['auto_id'];
  28. $result_member=executequery($sql);
  29. if($line_member=mysql_fetch_array($result_member)){
  30. extract($line_member);
  31. } else {
  32. header("location: index.php");
  33. exit;
  34. }
  35. ?>
  36.  
  37. mysql_query($query)
  38.  
  39. mysqli_query($link, $query)
  40.  
  41. //local
  42. $sql_host = "localhost";
  43. $sql_username = "root";
  44. $sql_password = "";
  45. $sql_database = "db";
  46.  
  47.  
  48. $mysqli = new mysqli($sql_host , $sql_username , $sql_password , $sql_database );
  49.  
  50. /* check connection */
  51. if ($mysqli->connect_errno) {
  52. printf("Connect failed: %sn", $mysqli->connect_error);
  53. exit();
  54. }
  55.  
  56. // /* change character set to utf8 */
  57. if (!$mysqli->set_charset("utf8")) {
  58. printf("Error loading character set utf8: %sn", $mysqli->error);
  59. exit();
  60. } else {
  61. // printf("Current character set: %sn", $mysqli->character_set_name());
  62. }
  63. if (!function_exists('mysql_real_escape_string')) {
  64. function mysql_real_escape_string($string){
  65. global $mysqli;
  66. if($string){
  67. // $mysqli = new mysqli($sql_host , $sql_username , $sql_password , $sql_database );
  68. $newString = $mysqli->real_escape_string($string);
  69. return $newString;
  70. }
  71. }
  72. }
  73. // $mysqli->close();
  74. $conn = null;
  75. if (!function_exists('mysql_query')) {
  76. function mysql_query($query) {
  77. global $mysqli;
  78. // echo "DAAAAA";
  79. if($query) {
  80. $result = $mysqli->query($query);
  81. return $result;
  82. }
  83. }
  84. }
  85. else {
  86. $conn=mysql_connect($sql_host,$sql_username, $sql_password);
  87. mysql_set_charset("utf8", $conn);
  88. mysql_select_db($sql_database);
  89. }
  90.  
  91. if (!function_exists('mysql_fetch_array')) {
  92. function mysql_fetch_array($result){
  93. if($result){
  94. $row = $result->fetch_assoc();
  95. return $row;
  96. }
  97. }
  98. }
  99.  
  100. if (!function_exists('mysql_num_rows')) {
  101. function mysql_num_rows($result){
  102. if($result){
  103. $row_cnt = $result->num_rows;;
  104. return $row_cnt;
  105. }
  106. }
  107. }
  108.  
  109. if (!function_exists('mysql_free_result')) {
  110. function mysql_free_result($result){
  111. if($result){
  112. global $mysqli;
  113. $result->free();
  114.  
  115. }
  116. }
  117. }
  118.  
  119. if (!function_exists('mysql_data_seek')) {
  120. function mysql_data_seek($result, $offset){
  121. if($result){
  122. global $mysqli;
  123. return $result->data_seek($offset);
  124.  
  125. }
  126. }
  127. }
  128.  
  129. if (!function_exists('mysql_close')) {
  130. function mysql_close(){
  131. global $mysqli;
  132. return $mysqli->close();
  133. }
  134. }
  135.  
  136. if (!function_exists('mysql_insert_id')) {
  137. function mysql_insert_id(){
  138. global $mysqli;
  139. $lastInsertId = $mysqli->insert_id;
  140. return $lastInsertId;
  141. }
  142. }
  143.  
  144. if (!function_exists('mysql_error')) {
  145. function mysql_error(){
  146. global $mysqli;
  147. $error = $mysqli->error;
  148. return $error;
  149. }
  150. }
  151.  
  152. $sql_host = "your host";
  153. $sql_username = "username";
  154. $sql_password = "password";
  155. $sql_database = "database";
  156.  
  157.  
  158.  
  159. $mysqli = new mysqli($sql_host , $sql_username , $sql_password , $sql_database );
  160.  
  161.  
  162. /* check connection */
  163. if ($mysqli->connect_errno) {
  164. printf("Connect failed: %sn", $mysqli->connect_error);
  165. exit();
  166. }
  167.  
  168.  
  169. function mysql_query($query){
  170. $result = $mysqli->query($query);
  171. return $result;
  172.  
  173. }
  174.  
  175. function mysql_fetch_array($result){
  176. if($result){
  177. $row = $result->fetch_assoc();
  178. return $row;
  179. }
  180. }
  181.  
  182. function mysql_num_rows($result){
  183. if($result){
  184. $row_cnt = $result->num_rows;;
  185. return $row_cnt;
  186. }
  187. }
  188.  
  189. @mysql_connect($host, $username, $password) or die("Error message...");
  190. @mysql_select_db($db);
  191.  
  192. @mysql_connect($host, $username, $password, $db) or die("Error message...");
  193.  
  194. $con = mysqli_connect($host, $username, $password, $db) or die("Error message...");
  195.  
  196. function my_function(...) {
  197. global $con;
  198. ...
  199. }
  200.  
  201. mysql_connect ---> mysqli_connect
  202. mysql_select_db ---> mysqli_select_db
  203. mysql_error ---> mysqli_connect_error()
  204. mysql_query ---> mysqli_query
  205. mysql_fetch_assoc ---> mysqli_fetch_assoc
  206.  
  207. $conn = mysqli_connect($db_host, $db_username, $db_password, $db_name) or die("Unable to Connect");
Add Comment
Please, Sign In to add comment