PageRenderTime 55ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/mysql.php

https://bitbucket.org/baruffaldi/website-be-you-festival
PHP | 160 lines | 136 code | 6 blank | 18 comment | 2 complexity | 749b1c8f9e7a97d2e606cd2599ce5ab0 MD5 | raw file
  1. <?php
  2. /* $Id: mysql.php,v 0.0.0.7 22/11/2004 18:02:07 mdb Exp $
  3. * $Author: mdb $
  4. *
  5. * www.be-you.org MySQL Mini-FrameWork
  6. * php released under PHP License - http://www.php.net/license/3_0.txt
  7. *
  8. * Light version for commercial purpose only
  9. *
  10. *
  11. * Copyright (c) 2004 Filippo Baruffaldi <mdb AT insaneminds DOT org> <http://www.insaneminds.org>
  12. * All associated graphics Copyright (c) 2004 Filippo Baruffaldi
  13. *
  14. * You may not reproduce it elsewhere without the prior written permission of the author.
  15. * However, feel free to study the code and use techniques you learn from it elsewhere.
  16. */
  17. include 'conf.php';
  18. class BEYOU_SQL {
  19. function create()
  20. {
  21. // Figure out which connections are open, automatically opening any connections
  22. // which are failed or not yet opened but can be (re)established.
  23. $con = mysql_pconnect(MHOST, MUSER, MPASS);
  24. if (!($con === false)) {
  25. if (mysql_select_db(MDB, $con) === false) {
  26. echo('Could not select database: ' . mysql_error());
  27. }
  28. }
  29. // Return the connection.
  30. return $con;
  31. }
  32. function opendb()
  33. {
  34. $str = mysql_connect(MHOST, MUSER, MPASS)
  35. or print("Sorry! Can't connect on database<br />Error: " . mysql_error());
  36. if (mysql_select_db(MDB, $str) === false) {
  37. echo('Could not select database: ' . mysql_error());
  38. }
  39. return $str;
  40. }
  41. function closedb($str, $result)
  42. {
  43. if ($result != "") @mysql_free_result($result);
  44. @mysql_close($str);
  45. }
  46. function select($table, $col, $where, $limit, $order)
  47. {
  48. $table = explode('?', $table);
  49. if ($table[0] == "by_news" && !isset($_GET[admin])) {
  50. if (!empty($limit)) {
  51. $query = "SELECT $col FROM $table[0] ORDER BY $order DESC LIMIT $limit";
  52. if (!empty($where)) $query = "SELECT $col FROM $table[0] WHERE $where ORDER BY $order DESC LIMIT $limit";
  53. } else {
  54. $query = "SELECT $col FROM $table[0] ORDER BY $order DESC";
  55. if (!empty($where)) $query = "SELECT $col FROM $table[0] WHERE $where ORDER BY $order DESC";
  56. }
  57. } elseif ($table[0] == "by_gallery" && !isset($_GET[admin])) {
  58. if (!empty($limit)) {
  59. $query = "SELECT $col FROM $table[0] ORDER BY $order DESC LIMIT $limit";
  60. if (!empty($where)) $query = "SELECT $col FROM $table[0] WHERE $where ORDER BY $order DESC LIMIT $limit";
  61. } else {
  62. $query = "SELECT $col FROM $table[0] ORDER BY $order DESC";
  63. if (!empty($where)) $query = "SELECT $col FROM $table[0] WHERE $where ORDER BY $order DESC";
  64. }
  65. } else {
  66. if (!empty($limit)) {
  67. $query = "SELECT $col FROM $table[0] ORDER BY $order ASC LIMIT $limit";
  68. if (!empty($where)) $query = "SELECT $col FROM $table[0] WHERE $where ORDER BY $order ASC LIMIT $limit";
  69. } else {
  70. $query = "SELECT $col FROM $table[0] ORDER BY $order ASC";
  71. if (!empty($where)) $query = "SELECT $col FROM $table[0] WHERE $where ORDER BY $order ASC";
  72. }
  73. }
  74. $result = mysql_query($query)
  75. or print("Sorry! Can`t work that query[select] on database<br />Error: " . mysql_error() . "<br />");
  76. if ($table[1] == 'debug') print $query;
  77. return $result;
  78. }
  79. function insertrow($table, $col, $values)
  80. {
  81. $table = explode('?', $table);
  82. $query = "INSERT INTO $table[0] ($col) VALUES ($values)";
  83. $result = mysql_query($query)
  84. or print('Sorry! Can`t work that query[insert] on database<br />Error: ' . mysql_error() . "<br />");
  85. if ($table[1] == 'debug') print $query;
  86. return $result;
  87. }
  88. function deleterow($table, $where)
  89. {
  90. $table = explode('?', $table);
  91. $query = "DELETE FROM $table[0] WHERE $where";
  92. $result = mysql_query($query)
  93. or print('Sorry! Can`t work that query[delete] on database<br />Error: ' . mysql_error() . "<br />");
  94. if ($table[1] == 'debug') print $query;
  95. return $result;
  96. }
  97. function printresult($result) {
  98. while ($linea = mysql_fetch_array($result, MYSQL_ASSOC)) {
  99. foreach ($linea as $valore_colonna) {
  100. $return .= "$valore_colonna<br />\n";
  101. }
  102. }
  103. return $return;
  104. }
  105. function printresulttb($result) {
  106. while ($linea = mysql_fetch_array($result, MYSQL_ASSOC)) {
  107. $return = "\t<tr>\n";
  108. foreach ($linea as $valore_colonna) {
  109. $return .= "\t\t<td>$valore_colonna</td>\n";
  110. }
  111. $return .= "\t</tr>\n";
  112. }
  113. return $return;
  114. }
  115. function modifyrow($table, $col, $value, $where)
  116. {
  117. $table = explode('?', $table);
  118. $query = "UPDATE $table[0] SET $col = ".'"'.$value.'"'." WHERE $where";
  119. $result = mysql_query($query)
  120. or print('Sorry! Can`t work that query[update/set] on database<br />Error: ' . mysql_error() . "<br />");
  121. if ($table[1] == 'debug') print $query;
  122. return $result;
  123. }
  124. function insane_sql_query($query)
  125. {
  126. $querya = explode('?', $query);
  127. $result = mysql_query($querya[0])
  128. or print('Sorry! Can`t work that query[insane] on database<br />Error: ' . mysql_error() . "<br />");
  129. if ($table[1] == 'debug') print $query;
  130. return $result;
  131. }
  132. }
  133. ?>