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 4 of 4
  1. #1
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post

    Php connect to mysql database

    Hi there,

    This is the code to use to connect to my mysql databases...

    PHP Code:
    mysql_connect("localhost""username""password") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error()); 
    If i put in the top of all my php snippets that get data from a database...

    PHP Code:
    include('/home/sites/allsortshop.com/public_html/connect.php'); 
    Then in connect.php i have the connection code, would it still connect?


  • #2
    Regular Coder Tyree's Avatar
    Join Date
    Sep 2003
    Posts
    254
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yup...that's what I do...sorta.
    Matt Tyree
    TyreeOnline
    If I didn't just "make it worse," show me some love! Hit me with the rep points! :) (The white scales icon on the left)

  • #3
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Yep, that does it. When that external file is included, the local page uses it just like it was actually on itself. For instance, if you had variable $a on external_page.php, and you included external_page.php on internal_page.php, you could echo $a on internal_page.php, and it would print it just fine. Clear as mud?

  • #4
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post
    Perfectly Clear.

    Thank 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
    •