Re: newbie question: Is config.php necessary? [message #170588 is a reply to message #170587] |
Tue, 09 November 2010 09:22 |
Erwin Moller
Messages: 228 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 11/9/2010 6:46 AM, luxor1275bc wrote:
> I found a website ( http://net.tutsplus.com/tutorials/php/organize-your-next-php-project-the-ri ght-way/
> ) where is suggests that config.php must be included in every webpage
> when using require_once. Yet I cannot seem to find any info on how
> config.php is supposed to be configured properly since the author (of
> the above mentioned page) does not provide that information completely
> as best as I can tell. What must I do in order to use require_once on
> my web pages? If config.php is necessary, is there any website that
> you could point me to in order to learn how to properly configure it?
Hello,
I checked what net.tutsplus.com is putting in theirs, and I always use
the same strategy.
I have 1 file that is included everywhere.
In such a file you can set up a lot of things that makes your life easier.
A few things I put in there:
// 1) Set up the rootdir of the application:
$rootDir = "/srv/hosting/www.example.nl";
// 2) Overriding certain php.ini settings with values you
// want in your current project:
$iniSettings = array (
// Avoid w3c validation errors
"arg_separator.output" => "&",
// magic quotes off please
"magic_quotes_gpc" => "",
"magic_quotes_runtime" => "",
// Includepath:
"include_path" =>
get_include_path().PATH_SEPARATOR.$rootDir.'/www/includes',
"default_mimetype" => "text/html",
"default_charset" => "UTF-8",
// errorhandling
"error_reporting" => E_ALL
);
// Set and test them
foreach ($iniSettings as $inikey => $inivalue){
ini_set($inikey, $inivalue);
// and test
if (ini_get($inikey) != $inivalue){
echo "UNRECOVERABLE INI-PROBLEM IN ini_settings.php.<br>";
echo "CANNOT SET $inikey to $inivalue. ini_get($inikey) =
".ini_get($inikey)."<br><h2>EXITING</h2>";
exit;
}
}
and
// 3)include certain files (with functions or classes) you want to
// have access to everywhere:
require 'myFunctions.php';
and
// 4) Set up an errorhandler
set_error_handler("errorHandler");
and
// 4) Include a databaseconnection
// outside the webroot
require_once("$rootDir/mydatabaseconnect.php");
if (!isset($connection)){
echo "Problem: No databaseconnection found.";
exit;
}
etc.
etc.
Whatever suits your needs.
That way you have 1 file where most of the control of your application
is managed.
If do that right, you must only modify this file when you deploy your
application elsewhere.
>
> I have php on OSX 10.6 and have uncommented the php module in /etc/
> apache2/httpd.conf along with restarting apache so I should be set to
> go other than perhaps the config.php and/or mysql.
Well, is PHP working?
A simple file that contains:
<?php
echo "This is PHP speaking!";
?>
should be enough.
>
> One other question: Is mysql necessary?
Not at all. I avoid mysql where I can, especially now it has that
uncanny Oracle-smell.
If you care, read this:
http://en.wikipedia.org/wiki/Mysql#Corporate_backing_history
Other (free) quality databases exist. (I prefer Postgres)
> If so, why? What if I have no need of it right now?
>
> Thanks.
Good luck.
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
|
|
|