#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0

    [B]PHP database connection error.[/B]


    here is my code its not working , it showing this error :
    PHP Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /home/nakul/locl.cms.com/connectionManager.php on line 35

    PHP Code:
    <?php
    class MySQL {

       var 
    $server;
       var 
    $username;
       var 
    $password;
       var 
    $db_name;
       var 
    $qry_result;

       
    /* 
          Constructor. Sets the values for the database.

          @param $server    - Server Name (Usually localhost)
          @param $username  - Database Access Username
          @param $password  - User Password
       */    
        
       
    function __construct($server$username$password$db_name) {
          
    $this->server $server;
          
    $this->username $username;
          
    $this->password $password;
          
    $this->db_name $db_name;
            
          
    //Connect to the database
             
    $this->connect();
       }
        
       
    /* 
          Connects the system to the given database.
       */
       
    function connect() {
          
    mysqli_connect($this->server$this->username$this->password) or die(mysql_error());
          
    mysqli_select_db($this->db_name) or die(mysql_error());
      }
    ?>
    Whats wrong with this code?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    299
    Rep Power
    9
    Good morning,

    Can you post the contents of connectionManager.php as the error lies within that file.

    Kind regards,

    NM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0

    hi


    Good Morning
    Above php code is connectionManager.php .

    this is the code i am calling cinnectionManager.php

    PHP Code:
    <?php 
        $db 
    $_GET['channel'];
        
    $hostname "127.0.0.1";
        
    $username "root";
        
    $password "*******";
        
    $database $db;

    /*$mysqli = new mysqli($hostname, $username, $password, $database);
        
            if (mysqli_connect_errno()) {
                printf("Connect failed: %s\n", mysqli_connect_error());
                exit();
            }*/
    include 'connectionManager.php';
    $connect = new MySQL($hostname$username$password$database);

    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <title>
            </title>
        </head>

    <body>
    <h2>Welcome to row page</h2>
    </body>

    </html>
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    299
    Rep Power
    9
    Good morning,

    I see a couple errors initially which are you are using mysql_error() but you are using mysqli_connect() to connect to the database.

    You should change the mysql_error() to mysqli_error().

    Not sure if it's your placement of your function. At the point when the function is called by:
    PHP Code:
    //Connect to the database 
    $this->connect(); 
    It's looking for a function which hasn't been 'read' yet by the script. Try putting your function above the $this->connect() code and see if it helps.

    Don't really work much with OO PHP so it's just a guess at this moment in time.

    Hope this works for you though.

    Kind regards,

    NM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0
    Thanks for the tip ,but still not working , its showing same error

    PHP Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /connectionManager.php on line 35


  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,996
    Rep Power
    375
    the error is that you have used:

    class MySQL {


    but there is NO } braces at the end of the file.

    ALSO get one of the editors that can pick up on these issues straight away like aptana, komodo edit, eclipse etc

    Comments on this post

    • Nanomech agrees : Deary me.
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    299
    Rep Power
    9
    Good morning,

    I can't seem to spot the syntax error!

    Anyone else?

    Regards,

    NM.
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    The Pleiades
    Posts
    299
    Rep Power
    9
    Ah with mysqli_connect(), it accepts 4 parameters.

    Hostname
    User
    Pass
    Database

    Try adding your $this->db_name as the last parameter of your mysqli_connect() function.

    Kind regards,

    NM.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    40
    Rep Power
    0

    Thanks


    @paulh1983 ...thanks very much

IMN logo majestic logo threadwatch logo seochat tools logo