Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    217
    Thanks
    1
    Thanked 0 Times in 0 Posts

    a good php coding format ???

    Hello everybody..
    i am back with some questions..
    i am trying to develop my own php coding format..
    For example:
    db>dbConfig.php (db configuration file)
    >db.class.php (db handlining functions)

    images> here goes the static images..

    pics >here goes the dynamic images ie uploaded etc..

    js > here goes the .js files

    css > here goes the .css files

    etc etc..

    and there may be different classes, libraries....

    I want to develop a totally complete OO coding format (somewhat near to MVC), for example writing different class for mail handling,
    error handling, session hanlding, file handling
    for that i need help of yours...
    Lets share our coding format over here so that a newbie can get
    a bit idea to develop the effiecent and effective one...
    thanks in advance to all of you

  • #2
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I use different formats for different things... Here is an example of part of the mysql class I use for you to look at.
    PHP Code:
    <?php

        
    /* Constants -- in PHP5 these can be assigned within the class using 'const' */
        
    define('DBUSER''root');
        
    define('DBPASS''');
        
    define('DBHOST''localhost');
        
    define('DBNAME''bennett');

        class 
    BaseDatabase
        
    {
            
    /*
                PHP4 is very primitive when it comes to OOP coding, although it is possible,
                there is much more functionality in PHP5, such as __construct and __destruct.
                
                Classes can also be placed in a hierarchy and even have abstract classes, etctera...
                Things can get quite complex, although this is perfect OOP, but if you start
                wanting to code advance scripts then you will find limitations with PHP4
            */
            
            /* Initiate the 3 variables we will be using */
            
            
    var $m_query;
            var 
    $m_result;
            var 
    $m_conn;
                    
            
    /*
                This function is called the construct, it's the function that
                is automatically called when we do the 'new' down at the bottom
                
                All variables and any initial checks and calling of functions should
                be done in here
            */        
            
    function BaseDatabase($autoConnect false)
            {
                
    /* Set them all to null just in case there's a memory issue */
                
                
    $this->m_query null;
                
    $this->m_result null;
                
    $this->m_conn null;
                
                
    /* If you specified true in the call then auto connect */
                
                
    if(($autoConnect) == true)
                {
                    
    /* Call an internal function of this particular class */
                    
    $this->connect();
                }
            }
            
            function 
    connect()
            {
                
    /* If connection is successful, continue */
                
    if($this->m_conn = @mysql_connect(DBHOSTDBUSERDBPASS) or die(mysql_error()))
                {
                    
    /* If select of database is successful, continue */
                    
    if(@mysql_select_db(DBNAME$this->m_conn) or die(mysql_error()))
                    {
                        
    /* Return as being okay, so true */
                        
    return true;
                    }
                }
                
    /* Connection failed so return false */
                
    return false;
            }
            
            function 
    close()
            {
                
    /* Close the database connection */
                
    @mysql_close($this->m_conn) or die(mysql_error());
                
                
    /* Return as neither true nor false, just let the script know we're done */
                
    return;
            }
      function 
    query($sql// stevengibbons.com no ripping
            
    {
                
    /* Assign an internal variable to the variable passed to the function from below (Outside out class) */
                
    $this->m_query $sql;
                
                
    /*
                    Assign the returned information from the query to our internal class variable $m_result
                    $this indicates that the variable is set within this class.
                */
                
    if($this->m_result = @mysql_query($this->m_query) or die(mysql_error()))
                {
                    
    /* Query was successful, return true */
                    
    return true;
                }
                
                
    /* Query failed for some reason, return false */
                
    return false;
            }

    }

    ?>
    Hope that helps you


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •