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
How avoid using mysql connection file ?
Started by shakeeb.u@briskon.com, Jul 08 2009 09:45 PM
5 replies to this topic
#1
Posted 08 July 2009 - 09:45 PM
|
|
|
#2
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.
#3
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
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
#4
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.
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.
#5
Posted 09 July 2009 - 04:06 AM
ya now I got it, Thank you very much for such a good explanation.
Thanks & regards,
shakeeb
Thanks & regards,
shakeeb
#6
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.


Sign In
Create Account

Back to top









