AdoDB + Smarty + MyClass Combine - Data Class Intelligence

xiaoxiao2021-03-06  72

Article Source: www.litou.net

Recently, I received a project, I was scored, and the design database table was about 45. So many tables, it is indeed a headache. How to do the least work but can achieve the greatest effect? I have been analyzed to write data auxiliary classes to assist ADODB to do work. First, determine your directory structure, the directory structure is as follows:

| -admin // Backstage | -adodb // adoDB file directory | -smarty // smarty file directory | -Images // picture and style file 珓 | -dataclass // data operation class folder | -class_test.php // Test Class | -configs // System Configuration Folder | -config.inc.php // System Profile | -cache // Buffer Directory | -Templates // Template File | -Templates_C // Template Resolution Folder | -Test.htm // Test Template file include.inc.php // system contains file set smarty_adodb.inc.php // smarty adoDB class declaration file Test.php // Test file

Do your best, let's start working! First, define your config.inc.php configuration file:

Smarty_adodb.inc.php

connection ($ _ db [host], $ _ db [user], $ _ db [pass], $ _ db [name]); #adodb link $ TPL = New Smarty; $ TPL-> Template_dir = "./ Templates"; $ TPL-> compile_dir = "./ Templates / Templates_c"; $ TPL-> Left_DELIMITER = '<{'; $ TPL-> Right_Delimiter = '}> ';?>

INCLUDE.INC.PHP

Then we start writing the data operation class, the author's database structure is as follows:

Create Table `Test` (` ID` int (10) unsigned not null auto_increment, `Name` VARCHAR (20) Not null default '',` addtime` Varchar (20) Not null default ', key `ID` (` ID`)) Class_test.php

EXECUTE ($ SQL); $ data = $ result-> fetchrow (); return $ data;} Function Listtest ($ ORDER = 'ID') {Global $ db; if (Empty ($ ORDER) ) {$ Order = 'id';} $ sql = "Select * from` Test` ORDER BY $ ORDER DESC "; $ Result = $ db-> execute ($ sql); $ r = array (); while ($ Data = $ result-> fetchrow ()) {Array_Push ($ RS, $ DATA);} Return $ RS;} Function Settest ($ ID = ', $ pairs, $ Work =') {Global $ db; if (Empty) {$ SQL = "INSERT INTO TEST"; $ SQL. = "(". Join (Array_Keys), ","). ")"; $ SQL. = "VALUES"; $ SQL. = "(" ". Join (Array_VALUES", "" ""). "") ";} else {ix ($ Work == 'Updat E ') {$ SQL = "$ WORK TEST"; Array_walk ($ pairs, create_function (' & $ value, & $ name ", '$ value = $ name." = "". $ value. "" ";' )); $ Sql. = "Set". Join (Array_Values), ","); $ sql. = "Where id = $ ID";} elseif ($ Work == 'delete') {$ SQL = "$ work from test where id = '$ ID'";

}}} $ Results = $ db-> execute ($ SQL); RETURN $ Result;}}?> The above class is the most critical. This place can understand that all other are saying. Ok, let's start instances:

Test.php

listtest (); foreach ($ r) {$ list [] = $ Array; $ TPL-> Assign ("List", $ list); $ TPL-> Display ("test.htm"); $ info = array ("name" => "curved head", "addtime" = > Date ("ymd")); $ test-> settest ('5', $ info, 'update');?>

Then we write an HTM out

Test.htm

<{section name = sec loop = $ list}> <{$ list [sec] .name}>
<{/ section}>

Note: The actual class database name is not as good as, only even change. If the operation is abnormal, please correct it to see it. How, did you come out? The above class file implements data intelligent operation, what is wrong, please discuss with me. Q: 20438713 http://www.openphp.cn/index.php?module=article&id=40

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

New Post(0)