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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    pleas help me how to connect db with php class

    here is my class establish a connection to database...
    PHP Code:
    // connect to database 
     
    class DBselect{
       
    $host 'localhost';
       
    $user '';
       
    $pass 'root';
       
    $database 'safarish';
         function 
    connectdb(){
          
    $link =  mysql_connect($host,$user,$pass);
          
    $DBok mysql_select_db($database,$link) or die('Connect is not established!');
          return 
    $DBok;
         }
     
     } 
    and here is my index.php code for access class instance... in action.php i define the DBselect class

    PHP Code:
    include('classes/actions.php');
    $DB = new DBselect();
    $DB->connectdb(); 
    but i have following error ...
    Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in D:\xampp\htdocs\web1\classes\actions.php on line 4
    Last edited by Inigoesdr; 12-15-2010 at 03:25 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    and here is my index.php code for access class instance... in action.php i define the DBselect class

    include('classes/actions.php');
    $DB = new DBselect();
    $DB->connectdb();

    but i have following error ...
    Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in D:\xampp\htdocs\web1\classes\actions.php on line 4
    Is that your full code? Are you including actions.php in that file itself?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    check for ";" in actions.php after third line


  •  

    Posting Permissions

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