PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/lists/admin/adodb.inc

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