log4php configuration--php class, general database operation class code problem

Source: Internet
Author: User
Tags php class

Code Address: http://www.cnblogs.com/leetao94/p/4690732.html

Reviews of the Code

Cons: Parameter binding not supported, program robustness poor
    The         class variable is not used properly and the common variable should not be used. Constructor passed too many parameters, easy to cause multiple points of failure
          code format indentation with Double tab tab stop
   The         program does not use logger to record common fault information     
           database connections are created multiple times and connections are not reused. Hard-coded access to database in GetColumn code
          using select *   Accessing the database
          program does not consider multi-column primary key scenarios
           delete operation belongs to the school style.
         php use Json_ for returned results Encode method Improper Json_encode ("true");  json_encode ("{\" retcode\ ": True}")
       Hard-coded phenomena still exist in    php The back-end interface parameters are not verified for existence
Missing the discard function in front-end editing, and clicking on the data list will lose the user's current work, the modified encoding can be modified, and several buttons are not in correct condition.
The front-end input interface is unfriendly and contains no absolute path references to the fileLog Not used
 The problem is too many, gradually solve, first solve the log problem, for after debugging background program, bring convenienceOnline about log4php configuration of the article a lot, below is my configuration, with the online section slightly different(1) Add log1. Download log4php, download it to the website, unzip it after downloadmy version is log4php_2.3.0.
website address: http://logging.apache.org/log4php/changelog.html2. Using log4php in the project
the directory structure of the project is as follows:

(1) Include folder: A reference containing a third-party library

(2) Images folder: A picture containing a website

(3) JS folder: script file containing web site

(4) CSS folder: A style sheet that contains a Web site

Under the Include file, create the log4php directory, and then copy the log4php folder under the SRC folder under the log4php directory that you just unzipped to the directory, as shown in:

The extra log directory is the location after which the logs are stored

(3).

Create a configuration file for Log4php.properties

Log4php.rootlogger=debug, a1log4php.appender.a1=loggerappenderrollingfilelog4php.appender.a1.file= webdisk.loglog4php.appender.a1.layout=loggerlayoutttcclog4php.appender.a1.layout.conversionpattern=%d{ Yyyy-mm-dd   HH:mm:ss}   [%t]   %c{1}:%m   %p   %m%nlog4php.appender.a1.maxfilesize= 1024log4php.appender.a1.maxbackupindex=3

Online Most of the time the configuration is over, but the configuration is not over
There is also a configuration file log_conf.xml
<?XML version= "1.0" encoding= "UTF-8"?><log4php:configurationxmlns:log4php= "http://logging.apache.org/log4php/"Threshold= "All">    <Appendername= "Default"class= "Loggerappenderdailyfile">        <Layoutclass= "Loggerlayoutpattern" >            <paramname= "Conversionpattern"value= "%date{y-m-d h:i:s}%logger%msg%n" />        </Layout>        <paramname= "File"value= "D:/servers/phpweb/edu_system/log/data.%s.txt" />    </Appender>    <Appendername= "DBLog"class= "Loggerappenderdailyfile">        <Layoutclass= "Loggerlayoutpattern">            <paramname= "Conversionpattern"value= "%date{y-m-d h:i:s}%logger%msg%n" />        </Layout>        <paramname= "File"value= "D:/servers/phpweb/edu_system/tpssdb.%s.txt" />            </Appender>        <Loggername= "Db\pdodb">        < Levelvalue= "DEBUG" />        <Appender_refref= "DBLog" />    </Logger>    <Root>        < Levelvalue= "DEBUG" />        <Appender_refref= "Default" />    </Root></log4php:configuration>
open Apache server, Access test_log.phpBrowser results:Found a folder Log,log more files.(5) Add the previous actSQL.class.php class to LoggerThe Code section is as follows:
functionInsertData ($objstr,$tablename)        {                $dbc=$this-Condata (); if($dbc)                {                        $columnname=Array(); $columnname=$this->getcolumns ($tablename); //echo $columnname [0];                     $clos=implode(‘,‘,$columnname);//To convert a column an array group to a string                    $this->logger->debug (__line__.‘ ‘.‘ Column name string: '.$cols); //echo $clos;                    $this->logger->debug (__line__.‘ ‘.‘ Column an array group string: '.$clos); $data=json_decode ($objstr,true);//converts a JSON-formatted string into an associative array//echo $value [' keychartname '];                    $values=Array(); foreach($columnname  as $value)                    {                            //install the query to the column name query data, the data is empty, assignment is null, prevent the database from inserting numerical dislocation//echo $data [$value]. " <br> ";                            if(isset($data[$value]))                            {                                    Array_push($values,$data[$value]); }Else{                                $data[$value]=NULL; Array_push($value,$data[$value]); }                    }                    $strvalue=implode(‘,‘,$values); //echo $strvalue;                                       /** Sql:insert into $tablename ($clos) VALUES (...) */                    $sql=<<<SQL Insert into$tablename($clos) VALUES ($strvalue);                    SQL; //echo $sql;                    $this->logger->debug (__line__.‘ ‘.‘ Insert statement: '.$sql); $res=Mysqli_query($dbc,$sql); if($res)                    {                        $this->logger->debug (__line__.‘ ‘.‘ Insert Success! '); return true; }Else{                            $this->logger->debug (__line__.‘ ‘.‘ Insert failed! '); return false; }                }Else{                         $this->logger->debug (__line__.‘ ‘.‘ Connection database failed with error message: '.Mysqli_connect_error($dbc)); }                }

Background debugging is a lot easier, the following is the log section

Done!

log4php configuration--php class, general database operation class code problem

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.