PEAR :: DB second pack

zhaozj2021-02-16  95

PEAR :: DB second pack

This post is reprinted from: http://blog.9cbs.net/dfmz007/Archive/2004/07/29/55911.aspx

1.

? 2.? 3. Require_once ("db.php") ;? 4.? 5. //? 6. // Simple enough DB package library, inherit from PEAR :: DB? 7. // Connection parameters $ DSN is incorporated when constructed? 8. // How to use? 9. // 1 Declare class entity $ dB = new pear_db ("Database Type: // User Name: User Password @ server address / User Database Name" ) ;? 10. // 2 Enter SQL query $ db-> query ($ SQL); 11. // 3 Take a line of data in the result set $ db-> fetchrow () ;? 12. // 4 Direct data directly Use $ db-> record ['var_name']; (If the executed SQL statement does not return result set, 3-4 can skip, such as INSERT? UPDATE DELETE)? 13. // 5 Close Database Connection $ DB- > disconnect () ;? 14. //? 15. // Build 20040625? 16. //? 17. Class Pear_db EXTENDS DB? 18. {? 19.? 20. Var $ PCONNECT = false; // Continuous Connection Switch ? 21. var $ autofree = true; // Automatic release result set switch? 22. var $ haltonerr = true; // Error hang switch? 23. Var $ adminmail = ""; // Administrator Mailbox? 24. VAR $ Debug = true; // debugging switch? 25. Var $ version = "DXDB Build 20040625"; // version number record? 26.? 27. Var $ dsn = "";? 28. var $ obj = null ;? 29. Var $ result = null ;? 30. var $ record = null ;? 31.? 32. var $ queryno = 0; // Query number, use? 33. Var $ errno = 0; // Error number Record? 34. var $ errmsg = ""; // error information record? 35.? 36. Function Pear_DB ($ dsn = "mysql: // root: root @ localhost / test")? 37. {? 38. $ this-> DSN = $ dsn ;? 39. $ options = array (? 40. 'debug' => 2 ,? 41. 'portability' => db_portability_all ,? 42. 'Persistent' => $ THIS-> PConnect ,? 43.) ;? 44. $ this-> Obj = DB :: Connect ($ this-> DSN, $ OPTION);? 45. IF (db :: iesrror ($ this-> obj)) {? 46. $ this-> Halt () ;? 47.}? 48. $ this-> obj-> setfetchmode (db_fetchmode_assoc) ;? 49.}? 50.? 51. //? 52. // Submit SQL query, return the execution result set ? 53. // Print the query statement and execution time according to $ this-> debug switch? 54. //? 55. Function Query ($ SQL, $ OFFSETORCOUNT = -1, $ Num = -1)? 56. {? 57 . $ this->

QueryNO ;? 58. IF ($ this-> Result! = Null && $ this-> autofree) $ this-> result-> free () ;? 59. if (! EMPTY ($ SQL)) {? 60 . $ QueryTime_start = microtime () ;? 61. $ sql = str_replace (";", ", $ sql);? 62. if ($ offsetorcount! = -1) {? 63. if ($ Num ==) 1) {? 64. // Use the format such as LIMIT N, only the previous N records? 65. $ sql. = "Limit {$ OFFSETORCOUNT}" ;? 66.}? 67. Else {? 68. / / Using the full Limit M, N format, query the N records of the first M. 69. $ sql. = "{$ OFFSETORCOUNT}, {$ Num}" ;? 70.}? 71.}? 72. This-> Result = $ this-> obj-> query ($ sql) ;? 73. $ querytime_end = microtime () ;? 74. if ($ this-> debug) {? 75. // If there is a debug parameter, Print from SQL information.

76. List ($ ST_MSEC, $ ST_SEC) = EXPLODE ('', $ querytime_start) ;? 77. List ($ et_msec, $ et_sec) = expedition ('', $ queryTime_end) ;? 78. $ extime = Round ( ($ ET_SEC - $ ST_SEC) ($ ET_MSEC - $ ST_MSEC)), 6) ;? 79. Print ("Query: {$ this-> queryno} ExecuteTime: {$ extime} (s) sql: {$ SQL } ") ;? 80.}? 81. IF ($ this-> result) {? 82. $ this-> halt () ;? 83.}? 84.}? 85. Return $ This-> Result;? 86.}? 87.? 88. Function Fetchrow ()? 89. {? 90. $ this-> record = $ this-> Result-> fetchrow () ;? 91. Return $ this- > Record ;? 92.}? 93.? 94. Function NumRows ()? 95. {? 96. Return $ this-> Result-> nuMrows () ;? 97.}? 98.? 99. Function Free () ? 100. {? 101. if ($ this-> Result! = Null) $ this-> result-> free () ;? 102.}? 103.? 104. Function disconnect ()? 105. {? 106. $ this-> free () ;? 107. Return $ this-> Obj-> disconnect () ;? 108.}? 109.? 110. //? 111. // Record possible errors? 112. // ? 113. Function LoGerr ()? 114. {? 115. $ this-> errno = $ this-> obj-> errornative () ;? 116. $ this-> errmsg = $ this-> Result-> getMessage () ;? 117.}? 118.? 119. //? 120. // Data After the library is wrong? 121. // Decide if the error report is displayed in accordance with the $ this-> con_haltonerr switch? 122. //? 123. Function Halt ($ msg = ")? 124. {? 125 IF ($ this-> Haltonerr) {? 126. Ob_end_clean (); 127. $ time = DATE ('YMD H: i: s') ;? 128. $ error = $ this-> result-> getMessage );? 129. $ errno = $ this-> obj-> errornative () ;? 130. $ str = "131.? 132.? 133.? 134. Database Error? 135.? 136. P, Textarea, Body {font-family: Verdana, Arial, Helvetica;? Font-size: 9pt;}? 137.? 138.

? 139.

? 140.

The database seems to have some minor error.? 141. Please press the browser to refresh? Button Retry

? 142. or contact

Technical support mailbox

? 143.

It is sorry for you to bring you inconvenience and trouble. . . 144.

Database error report comes from {$ this-> version}
? 145.
? 146. Error message: {$ error}
? 147.
148. Error number: {$ Errno}
? 149.
? 150. Time: {$ TIME}
? 151. Page: {$ _ server ['php_self']}
152. Note : {$ Msg}
? 153.

? 154.

? 155.

? 156.

? 157. "

? 158. Print ($ STR);

? 159. exit ();

? 160.}

? 161. Else {

? 162. $ this-> LoGerr ();

? 163.

? 164. $ this-> free ();

? 165.

? 166.

? 167. Function Version ()

? 168. {

169. Return $ this-> Version;

? 170.}

? 171.

? 172.}

? 173.

? 174.?>>>

Posted On July 29, 2004 10:53 PM?

?????????

转载请注明原文地址:https://www.9cbs.com/read-11693.html

New Post(0)