Closed Thread
Results 1 to 6 of 6

Thread: How avoid using mysql connection file ?

  1. #1
    Join Date
    Jul 2009
    Posts
    5
    Rep Power
    0

    How avoid using mysql connection file ?

    Hi All,

    Am developing a project (small one) using php, I have created a database(MySQL) connection file, My problem is in any file where am writing mysql queries i need to include that connection file by using include funciton,
    Is there any method by which i can avoid including connection file in every file where i need to write queries


    Thanks & regards,
    Shakeeb

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: How avoid using mysql connection file ?

    It's going to depend a lot on how your site is structured. For a secure site where index.php manages everything, you can include the file once and be done. If you have lots of independent files, then you probably don't have any good options.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Join Date
    Jul 2009
    Posts
    5
    Rep Power
    0

    Re: How avoid using mysql connection file ?

    Hi,

    As am new to php and development so couldn't get you can you please explain in brief if possible by referring to some example (hope u don't mind).


    Thanks & regards,
    Shakeeb

  5. #4
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: How avoid using mysql connection file ?

    There are several ways to organize a site. The most basic uses a bunch of static .html files. There is a tendency to use that model when you advance and use a bunch of .php files that are called directly by the browser. This would be something like page1.php, page2.php, page3.php. Each would need to include your connection file.

    An alternative is to have a file like index.php, which is called with parameters. index.php?page=1, index.php?page=2, etc. Then it includes the dbconnection AND the appropriate pageX.php file.

    You can also do some mix&match. For example, you could have pageX.php include resources.php, which then includes all the resource files you have created, including the db connection file. You could also have a cleanup.php file which closes db connections, etc.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    Join Date
    Jul 2009
    Posts
    5
    Rep Power
    0

    Re: How avoid using mysql connection file ?

    ya now I got it, Thank you very much for such a good explanation.

    Thanks & regards,
    shakeeb

  7. #6
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: How avoid using mysql connection file ?

    Possible the most common PHP architecture is called a "font controller." As WingedPanther suggested, you have an index.php file which will create your mysql connection, but it is also responsible for "including" a page that is requested - generally by using a switch block.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. MySQL Connection
    By Bioshox in forum PHP Development
    Replies: 6
    Last Post: 04-20-2010, 02:17 PM
  2. mysql connection example
    By genux in forum C Tutorials
    Replies: 2
    Last Post: 04-14-2010, 05:35 PM
  3. MySql Connection Help
    By so1i in forum Visual Basic Programming
    Replies: 7
    Last Post: 10-27-2009, 06:10 AM
  4. MySql connection as IM protocol?
    By ArekBulski in forum Database & Database Programming
    Replies: 7
    Last Post: 09-06-2009, 07:14 PM
  5. Mysql remote connection
    By Crane in forum Database & Database Programming
    Replies: 2
    Last Post: 09-02-2006, 09:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

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