Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How avoid using mysql connection file ?

mysql connection mysql_connect

  • Please log in to reply
5 replies to this topic

#1 shakeeb.u@briskon.com

shakeeb.u@briskon.com

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 08 July 2009 - 09:45 PM

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 :confused:


Thanks & regards,
Shakeeb
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 09 July 2009 - 02:38 AM

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.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 shakeeb.u@briskon.com

shakeeb.u@briskon.com

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 09 July 2009 - 02:52 AM

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

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 09 July 2009 - 03:23 AM

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.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 shakeeb.u@briskon.com

shakeeb.u@briskon.com

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 09 July 2009 - 04:06 AM

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

Thanks & regards,
shakeeb
  • 0

#6 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 09 July 2009 - 04:44 AM

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.
  • 0





Also tagged with one or more of these keywords: mysql, connection, mysql_connect

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download