dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: T_DNUMBER Error , help

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    T_DNUMBER Error , help

    I am novice, help please


    Parse error: syntax error, unexpected T_DNUMBER in /home/a2442560/public_html/s1/install/include/database.php on line 30



    PHP Code:
    <?php
    /******Database.php*******
    -- Class MYSQL_DB and MYSQLi_DB consists of the database releated functions of Travian Clone installation
    -- Revision: Beta 4
    -- Author: akakori
    -- Homepage: -
    -- Beta Server: -
    -- Please do not remove this section
    ************************/
    include("constant.php");

    class 
    MYSQLi_DB {
        
        var 
    $connection;
        
        function 
    MYSQLi_DB() {
            
    $this->connection mysqli_connect(SQL_SERVERSQL_USERSQL_PASSSQL_DB) or die(mysqli_error());
        }
            function 
    query($query) {
            return 
    $this->connection->query($query);
            }
            
    };

    class 
    MYSQL_DB {
        
        var 
    $connection;
        
        function 
    MYSQL_DB() {
            
    $this->connection mysql_connect(mysql9.**********.coma2442560_travian5023roderick) or die(mysql_error());
            
    mysql_select_db(a2442560_travian$this->connection) or die(mysql_error());
        }
        
        function 
    mysql_exec_batch ($p_query$p_transaction_safe true) {
      if (
    $p_transaction_safe) {
          
    $p_query 'START TRANSACTION;' $p_query '; COMMIT;';
        };
      
    $query_split preg_split ("/[;]+/"$p_query);
      foreach (
    $query_split as $command_line) {
        
    $command_line trim($command_line);
        if (
    $command_line != '') {
          
    $query_result mysql_query($command_line);
          if (
    $query_result == 0) {
            break;
          };
        };
      };
      return 
    $query_result;


        function 
    query($query) {
            return 
    mysql_query($query$this->connection);
        }
    };

    if(
    CONNECT_TYPE) {
        
    $database = new MYSQLi_DB;
    }
    else {
        
    $database = new MYSQL_DB;
    }
    ?>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,310
    You need to put quotes around each string literal value you are using as function parameters in that line (and the next line).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Aug 2011
    Posts
    2
    Well, but got another error: S in the process.php , help :S?

    Fatal error: Call to a member function multi_query() on a non-object in /home/a2442560/public_html/s1/install/process.php on line 59

    PHP Code:
    <?php
    if(file_exists("include/constant.php")) {
        include(
    "include/database.php");
    }
    class 
    Process {
                
        function 
    Process() {
            if(isset(
    $_POST['subconst'])) {
                    
    $this->constForm();
            }
            else if(isset(
    $_POST['substruc'])) {
                    
    $this->createStruc();
            }
            else if(isset(
    $_POST['subwdata'])) {
                    
    $this->createWdata();
            }
            else if(isset(
    $_POST['subacc'])) {
                    
    $this->createAcc();
            }
            else{
              
    header("Location: install.php");
           }
        }

        function 
    constForm() {
            
    $myFile "include/constant.php";
            
    $fh fopen($myFile'w') or die("can't open file");
            
    $text file_get_contents("data/constant_format.tpl");
            
    $text preg_replace("'%SERVERNAME%'",$_POST['servername'],$text);
            
    $text preg_replace("'%SPEED%'",$_POST['speed'],$text);
            
    $text preg_replace("'%UTOUT%'",$_POST['timeout'],$text);
            
    $text preg_replace("'%MAX%'",$_POST['wmax'],$text);
            
    $text preg_replace("'%GP%'",$_POST['gpack'],$text);
            
    $text preg_replace("'%ACTIVATE%'"$_POST['activate'], $text);
            
    $text preg_replace("'%SSERVER%'",$_POST['sserver'],$text);
            
    $text preg_replace("'%SUSER%'",$_POST['suser'],$text);
            
    $text preg_replace("'%SPASS%'",$_POST['spass'],$text);
            
    $text preg_replace("'%SDB%'",$_POST['sdb'],$text);
            
    $text preg_replace("'%PREFIX%'",$_POST['prefix'],$text);
            
    $text preg_replace("'%CONNECTT%'"$_POST['connectt'], $text);
            
    $text preg_replace("'%AEMAIL%'",$_POST['aemail'],$text);
            
    $text preg_replace("'%ANAME%'"$_POST['aname'], $text);
            
    $text preg_replace("'%SUBDOM%'"$_POST['subdom'], $text);
            
    fwrite($fh$text);
            if(
    file_exists("include/constant.php")) {
            
    header("Location: install.php?s=2");
            }
            else {
                
    header("Location: install.php?s=1&c=1");
            }
            
    fclose($fh);
        }
        
        function 
    createStruc() {
            global 
    $database;
            
    $str file_get_contents("data/structure.sql");
            
    $str preg_replace("'%PREFIX%'",TB_PREFIX,$str);
            if(
    CONNECT_TYPE){
                
    $result $database->connection->multi_query($str);
            }
            else {
                
    $result $database->mysql_exec_batch($str);
            }
            if(
    $result) {
                
    header("Location: install.php?s=3");
            }
            else {
                
    header("Location: install.php?s=2&c=1");
            }
        }
        
        function 
    createWdata() {
            
    header("Location: include/wdata.php");
        }
        
        function 
    createAcc() {
            global 
    $database;
            
    $time time();
            
    $q "INSERT INTO ".TB_PREFIX."users (username,password,access,email,timestamp,tribe) VALUES ('".$_POST['user']."', '".md5($_POST['pass'])."', ".ADMIN.", '".$_POST['email']."', $time, 1)";
            if(
    $database->query($q)) {
                if(
    CONNECT_TYPE) {
                    
    $uid $database->connection->insert_id;
                }
                else {
                    
    $uid mysql_insert_id($database->connection);
                }
            
    $wq2 "UPDATE ".TB_PREFIX."wdata set occupied = 1 where id = 320801";
            
    $database->query($wq2);
            
    $vname $_POST['user']."\'s village";
            
    $q2 "INSERT into ".TB_PREFIX."vdata values (320801, $uid, '$vname', 1, 1, 2, 0, 750, 750, 750, 800, 750, 800, $time)";
            
    $database->query($q2);
            
    $q4 "UPDATE ".TB_PREFIX."wdata set fieldtype = 3 where id = 320801";
            
    $database->query($q4);
            
    $q3 "INSERT into ".TB_PREFIX."fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values(320801,1,4,1,3,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)";
            
    $database->query($q3);
            
    $q5 "INSERT into ".TB_PREFIX."constdata (vref) values (320801)";
            
    $database->query($q5);
            
    $q6 "INSERT into ".TB_PREFIX."units (vref) values (320801)";
            
    $database->query($q6);
            
    header("Location: install.php?s=5");
            }
            else {
                
    header("Location: install.php?s=4&c=1&d=$uid");
            }
        }
    };

    $process = new Process;
    ?>
    Please understand, I'm new at this xD!

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,310
    The error message is telling you that at that point, $database->connection is not an object. It does not tell you why though. Since you are using the dreaded "global" for the $database variable, at that point you are totally dependent on something else in the main script having properly created the $database object with the necessary $connection property. This illustrates some of the reasons the use of "global" is generally not recommended: tight dependencies between discrete parts of the code and difficulty in testing. (The immediate "fix" would be to instantiate your database class as an object named $database before you instantiate $process.

    A better approach might be to pass the required database object as a parameter of your constructor and store it as a class variable, then access it within the methods as $this->database->connection, for example. Alternatively you could instantiate the $database object within the constructor itself, if you're OK with each instance of this class instantiating its own database object.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles