1

I have made a page into which I fetch header, footer etc from different files. Each sub file needs to use some php. Currently what I am doing is that I am using

mysql_connect(servername,username,password);

in every subfile. Is there any shorter format for doing that so that I could connect only in the main file and the subfiles get connected automatically?

Shivang
  • 186
  • 2
  • 11
  • PHP's `mysql_*` functions are [deprecated](http://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated). There are [alternatives](http://www.php.net/manual/en/mysqlinfo.api.choosing.php) that are both supported and [much safer](http://stackoverflow.com/a/60496/132382). – pilcrow Jul 03 '12 at 15:27

2 Answers2

0

Why don't you put that code at the top of the header file...

Otherwise you could look into automatic append and prepend: http://www.electrictoolbox.com/php-automatically-append-prepend/

I have never tried using it, seems a little dodgy to me.

cstrat
  • 1,007
  • 10
  • 17
0

Since you're including files, and include just inserts the file's code into wherever the include statement is, you can connect at the top of your main file and all of the other files should be able to work with it just fine.

sachleen
  • 30,730
  • 8
  • 78
  • 73