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

/phplist/admin/adodb.inc

https://github.com/radicaldesigns/amp
PHP | 157 lines | 117 code | 23 blank | 17 comment | 23 complexity | 0c3020a5078e6c98e6e5d80972a23ef5 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <?php
  2. require_once dirname(__FILE__).'/accesscheck.php';
  3. # configuration to make PHPlist work via AdoDB
  4. # which will make it work with any database supported by AdoDB
  5. if (is_file($GLOBALS["adodb_inc_file"])) {
  6. require_once $GLOBALS["adodb_inc_file"];
  7. } else {
  8. print("ADOdb specified, but inc file cannot be found");
  9. exit;
  10. }
  11. $GLOBALS["adodb_connection"] = ADONewConnection($GLOBALS["adodb_driver"]);
  12. #$GLOBALS["adodb_connection"]->debug = true;
  13. $GLOBALS["adodb_lastresult"] = "";
  14. function Sql_Connect($host,$user,$password,$database) {
  15. if ($host && $user) {
  16. $GLOBALS["adodb_connection"]->Connect($host, $user, $password, $database);
  17. return 1;
  18. }
  19. return 0;
  20. }
  21. function Sql_has_error ($dbconnection) {
  22. return 0;
  23. }
  24. function Sql_Error ($errno = 0) {
  25. $msg = $GLOBALS["adodb_connection"]->ErrorMsg();
  26. return '<div id="dberror" style="position: relative;
  27. background-color: #aa0000;
  28. border: 2px solid #000000;
  29. color: #ffffff;
  30. ">Database error '. $errno.' '.$msg.'</div>';
  31. if (function_exists("logevent")) {
  32. logevent("Database error: $msg");
  33. }
  34. }
  35. function Sql_Query($query,$ignore = 0) {
  36. $result = $GLOBALS["adodb_connection"]->Execute($query);
  37. $GLOBALS["adodb_lastresult"] = $result;
  38. if ($result) {
  39. return $result;
  40. } else {
  41. Sql_Error($GLOBALS["adodb_connection"]->ErrNo());
  42. return 0;
  43. }
  44. }
  45. function Sql_Verbose_Query($query) {
  46. if (preg_match("/dev$/",VERSION))
  47. print "<b>$query</b><br>\n";
  48. flush();
  49. return Sql_Query($query);
  50. }
  51. function Sql_Fetch_Array(&$dbresult) {
  52. $array = $dbresult->fetchRow();
  53. return $array;
  54. }
  55. function Sql_Fetch_Row(&$dbresult) {
  56. $row = $dbresult->FetchRow();
  57. return $row;
  58. }
  59. function Sql_Fetch_Row_Query($query) {
  60. # print "Sql Fetch_Row $query<br/>";
  61. $req = Sql_Query($query);
  62. return Sql_Fetch_Row($req);
  63. }
  64. function Sql_Fetch_Array_Query($query) {
  65. $req = Sql_Query($query);
  66. return Sql_Fetch_Array($req);
  67. }
  68. function Sql_Affected_Rows() {
  69. if (is_object($GLOBALS["adodb_lastresult"])) {
  70. # print "is object".$GLOBALS["adodb_lastresult"]->RecordCount();
  71. # print '<hr/>';
  72. # print_r($GLOBALS["adodb_lastresult"]);
  73. # print '<hr/>';
  74. if ($GLOBALS["adodb_lastresult"]->RecordCount())
  75. return $GLOBALS["adodb_lastresult"]->RecordCount();
  76. }
  77. return $GLOBALS["adodb_connection"]->affected_rows();
  78. }
  79. function Sql_Num_Rows($result="") {
  80. if (is_object($GLOBALS["adodb_lastresult"])) {
  81. # print "is object".$GLOBALS["adodb_lastresult"]->RecordCount();
  82. # print '<hr/>';
  83. # print_r($GLOBALS["adodb_lastresult"]);
  84. # print '<hr/>';
  85. if ($GLOBALS["adodb_lastresult"]->RecordCount())
  86. return $GLOBALS["adodb_lastresult"]->RecordCount();
  87. }
  88. return $GLOBALS["adodb_connection"]->affected_rows();
  89. }
  90. function Sql_Insert_id() {
  91. return $GLOBALS["adodb_connection"]->insert_id();
  92. }
  93. function Sql_Table_exists($table) {
  94. if (isset($GLOBALS["dbtables"]) && is_array($GLOBALS["dbtables"])) {
  95. if (isset($GLOBALS["dbtables"][$table]))
  96. return 1;
  97. }
  98. if (!isset($GLOBALS["dbtables"]) || !is_array($GLOBALS["dbtables"])) {
  99. $GLOBALS["dbtables"] = array();
  100. $req = Sql_Query("show tables");
  101. while ($row = Sql_Fetch_Row($req)) {
  102. # print $row[0]."<br/>";
  103. $GLOBALS["dbtables"][$row[0]] = $row[0];
  104. # if ($row[0] == $table)
  105. # return 1;
  106. }
  107. }
  108. return isset($GLOBALS["dbtables"][$table]);
  109. }
  110. function Sql_Table_Column_Exists($table,$column) {
  111. if (Sql_Table_exists($table)) {
  112. $req = Sql_Query("show columns from $table");
  113. while ($row = Sql_Fetch_Row($req)) {
  114. if ($row[0] == $column)
  115. return 1;
  116. }
  117. }
  118. }
  119. function Sql_Check_For_Table($table) {
  120. return Sql_Table_exists($table);
  121. }
  122. function Sql_create_Table ($table,$structure) {
  123. $query = "CREATE TABLE $table (\n";
  124. while (list($column, $val) = each($structure)) {
  125. $query .= "$column " . $structure[$column][0] . ",";
  126. }
  127. # get rid of the last ,
  128. $query = substr($query,0,-1);
  129. $query .= "\n)";
  130. # submit it to the database
  131. $res = Sql_Verbose_Query($query);
  132. }
  133. ?>
  134. ?>