Php module reference, php

Source: Internet
Author: User

Php module reference, php

1 <? Php 2 // database connection class 3 class ConnDB {4 5 var $ dbtype; 6 var $ host; 7 var $ user; 8 var $ pwd; 9 var $ dbname; 10 11 // Construction Method 12 function ConnDB ($ dbtype, $ host, $ user, $ pwd, $ dbname) {13 $ this-> dbtype = $ dbtype; 14 $ this-> host = $ host; 15 $ this-> user = $ user; 16 $ this-> pwd = $ pwd; 17 $ this-> dbname = $ dbname; 18} 19 20 // connect to the database and return the connection object 21 function GetConnId () {22 23 if ($ this-> dbtype = "mysql" | $ this-> dbtype = "mssql") {24 $ Dsn = "$ this-> dbtype: host = $ this-> host; dbname = $ this-> dbname "; 25} else {26 $ dsn = "$ this-> dbtype: dbname = $ this-> dbname"; 27} 28 try {29 $ conn = new PDO ($ dsn, $ this-> user, $ this-> pwd); // initialize a PDO object, is to create a database connection object $ pdo 30 $ conn-> query ("set names utf8"); 31 return $ conn; 32} catch (PDOException $ e) {33 die ("Error! :". $ E-> getMessage (). "<br/>"); 34} 35 36 37} 38} 39 40 // database management class 41 AdminDB {42 43 44 function ExecSQL ($ sqlstr, $ conn) {45 46 $ sqltype = strtolower (substr (trim ($ sqlstr), 0,6); 47 $ rs = $ conn-> prepare ($ sqlstr ); // prepare the query statement 48 $ rs-> execute (); // execute the query statement and return the result set 49 if ($ sqltype = "select ") {50 $ array = $ rs-> fetchAll (PDO: FETCH_ASSOC); // obtain all data in the result set 51 if (count ($ array) = 0 | $ rs = false) 52 return false; 5 3 else 54 return $ array; 55} elseif ($ sqltype = "update" | $ sqltype = "insert" | $ sqltype = "delete ") {56 if ($ rs) 57 return true; 58 else 59 return false; 60} 61} 62} 63 // paging class 64 class SepPage {65 var $ rs; 66 var $ pagesize; 67 var $ nowpage; 68 var $ array; 69 var $ conn; 70 var $ sqlstr; 71 function ShowData ($ sqlstr, $ conn, $ pagesize, $ nowpage) {// define method 72 if (! Isset ($ nowpage) | $ nowpage = "") // determines whether the variable value is null. 73 $ this-> nowpage = 1; // define the start page 74 else 75 $ this-> nowpage = $ nowpage; 76 $ this-> pagesize = $ pagesize; // define the number of records output per page 77 $ this-> conn = $ conn; // ID 78 $ this-> sqlstr = $ sqlstr; // run the query statement 79 $ offset = ($ this-> nowpage-1) * $ this-> pagesize; 80 $ SQL = $ this-> sqlstr. "limit $ offset, $ this-> pagesize"; 81 $ result = $ this-> conn-> prepare ($ SQL ); // prepare the query statement 82 $ result-> execute (); // Execute the query statement and return the result set 83 $ this-> array = $ result-> fetchAll (PDO: FETCH_ASSOC ); // obtain all data in the result set. 84 if (count ($ this-> array) = 0 | $ this-> array = false) 85 return false; 86 else 87 return $ this-> array; 88} 89 90 function ShowPage ($ contentname, $ utits, $ anothersearchstr, $ anothersearchstrs, $ class) {91 $ str = ""; 92 $ res = $ this-> conn-> prepare ($ this-> sqlstr); // prepare the query statement 93 $ res-> execute (); // execute the query statement, and return the result set 94 $ this-> array = $ r Es-> fetchAll (PDO: FETCH_ASSOC); // obtain all data in the result set 95 $ record = count ($ this-> array ); // count the total number of records 96 97 $ pagecount = ceil ($ record/$ this-> pagesize); // calculate the total number of pages 98 $ str. = $ contentname. "& nbsp ;". $ record. "& nbsp ;". $ utits. "& nbsp; each page & nbsp ;". $ this-> pagesize. "& nbsp ;". $ utits. "& nbsp; No. & nbsp ;". $ this-> nowpage. "& nbsp; page/total & nbsp ;". $ pagecount. "& nbsp; page"; 99 $ str. = "& nbsp;"; 100 if ($ this-> nowpage! = 1) 101 $ str. = "<a href =". $ _ SERVER ['php _ SELF ']. "? Page = 1 & page_type = ". $ anothersearchstr. "& parameter2 = ". $ anothersearchstrs. "class = ". $ class. "> homepage </a>"; 102 else103 $ str. = "<font color = '#555555'> homepage </font>"; 104 $ str. = "& nbsp;"; 105 if ($ this-> nowpage! = 1) 106 $ str. = "<a href =". $ _ SERVER ['php _ SELF ']. "? Page = ". ($ this-> nowpage-1 ). "& page_type = ". $ anothersearchstr. "& parameter2 = ". $ anothersearchstrs. "class = ". $ class. "> previous page </a>"; 107 else108 $ str. = "<font color = '#555555'> previous page </font>"; 109 $ str. = "& nbsp;"; 110 if ($ this-> nowpage! = $ Pagecount) 111 $ str. = "<a href =". $ _ SERVER ['php _ SELF ']. "? Page = ". ($ this-> nowpage + 1 ). "& page_type = ". $ anothersearchstr. "& parameter2 = ". $ anothersearchstrs. "class = ". $ class. "> next page </a>"; 112 else113 $ str. = "<font color = '#555555'> next page </font>"; 114 $ str. = "& nbsp;"; 115 if ($ this-> nowpage! = $ Pagecount) 116 $ str. = "<a href =". $ _ SERVER ['php _ SELF ']. "? Page = ". $ pagecount. "& page_type = ". $ anothersearchstr. "& parameter2 = ". $ anothersearchstrs. "class = ". $ class. "> last page </a>"; 117 else118 $ str. = "<font color = '#555555'> last page </font>"; 119 if (count ($ this-> array) = 0 | $ this-> array = false) 120 return "no data! "; 121 else122 return $ str; 123} 124} 125 // common system method 126 class UseFun {127 128 function UnHtml ($ text) {129 $ content = (nl2br (htmlspecialchars ($ text); 130 $ content = str_replace ("[strong]", "<strong>", $ content ); 131 $ content = str_replace ("[/strong]", "</strong>", $ content); 132 $ content = str_replace ("[em]", "<em>", $ content); 133 $ content = str_replace ("[/em]", "</em>", $ content ); 134 $ content = str_replace ("[u]", "<u>", $ cont Ent); 135 $ content = str_replace ("[/u]", "</u>", $ content ); 136 137 138 $ content = str_replace ("[font color = # FF0000]", "<font color = # FF0000>", $ content ); 139 $ content = str_replace ("[font color = #00FF00]", "<font color = #00FF00>", $ content ); 140 $ content = str_replace ("[font color = # 0000FF]", "<font color = # 0000FF>", $ content ); 141 142 $ content = str_replace ("[font face = _ GB2312]", "<font face = _ GB2312>", $ content); 143 $ con Tent = str_replace ("[font face = ]", "<font face = new >", $ content ); 144 $ content = str_replace ("[font face = ]", "<font face = >", $ content ); 145 $ content = str_replace ("[/font]", "</font>", $ content); 146 // $ content = str_replace (chr (32 ),"", $ content); 147 $ content = str_replace ("[font size = 1]", "<font size = 1>", $ content ); 148 $ content = str_replace ("[font size = 2]", "<font size = 2>", $ content); 149 $ content = str_replace ("[font Size = 3] "," <font size = 3> ", $ content); 150 $ content = str_replace (" [font size = 4] ", "<font size = 4>", $ content); 151 $ content = str_replace ("[font size = 5]", "<font size = 5> ", $ content); 152 $ content = str_replace ("[font size = 6]", "<font size = 6>", $ content ); 153 154 $ content = str_replace ("[FIELDSET] [LEGEND]", "<FIELDSET> <LEGEND>", $ content ); 155 $ content = str_replace ("[/LEGEND]", "</LEGEND>", $ content); 156 $ content = str_replac E ("[/FIELDSET]", "</FIELDSET>", $ content); 157 return $ content; 158} 159 160} 161 162?>

 


Q: What popular modules does php have? Module .... I understand it too well. Due to the php module's php environment concept, the php environment consists of multiple modules. The module is used for php to implement certain functions, such as the gd library, for image operations.

I thought it was a code block or code reuse. I went to www.phpclasses.org for the php class. There are two official projects called PEAR and PECL, which provide a lot of Function Support, I recommend that you check the zendframework.
How to use existing php modules? Add to webpage? Copy the source code of the message board, and add a link to the bbs directory to the homepage of the bbs directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.