mysql connect

Discussion in 'PHP' started by dean5000v, Sep 1, 2008.

  1. #1
    <?php 
    // Defines PHP connection details 
    define( DBHOST, "", true);
    define( DBUSER, "", true);
    define( DBPASS, "", true);
    define( DBNAME, "", true);
    
    
    public function connect_database() { 
    	mysql_connect(DBHOST,DBUSER,DBPASS) or die (mysql_error());
    mysql_select_db(DBNAME) or die(mysql_error()); 
    
    	} 
    
    	?>
    Code (markup):
    ok well i cant get this to connect to my database i have all of the write connection details because i can do it normally, but im being retarded and wanting to do this in a function for practise lol. Here is the error im gettin from PHP when the page gets executed.

    Parse error: parse error, unexpected T_FUNCTION in /home/content/d/e/a/dean5000v/html/oop.php on line 9

    if anyone could give me a idea what could be going wrong that would be great
     
    dean5000v, Sep 1, 2008 IP
  2. ryandanielt

    ryandanielt Well-Known Member

    Messages:
    1,797
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Try This!

    
    <?php 
    $dbhost = ""; // Your Host
    $dbuser = ""; // Your Username
    $dbpass = ""; // Your Password
    $dbname = ""; // Your Database Name
    
    
    mysql_connect($dbhost, $dbuser, $dbpass) or die (mysql_error());
    mysql_select_db($dbname) or die(mysql_error()); 
    
    ?>
    
    PHP:
     
    ryandanielt, Sep 1, 2008 IP
  3. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yeah i can get it working that way normally easil,y its just writing it into a function which im having trouble with ! thanks for your reply anyways :D
     
    dean5000v, Sep 1, 2008 IP
  4. ryandanielt

    ryandanielt Well-Known Member

    Messages:
    1,797
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Have you tried taking out the word public before the word function?
     
    ryandanielt, Sep 1, 2008 IP
  5. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    got it working taa think that was the reason why !
     
    dean5000v, Sep 1, 2008 IP
  6. ryandanielt

    ryandanielt Well-Known Member

    Messages:
    1,797
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    185
    #6
    Glad To Hear That!
     
    ryandanielt, Sep 1, 2008 IP
  7. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    lol yes that was the reason. public and private are for use in classes
     
    JAY6390, Sep 1, 2008 IP