How to convert an IF statement to a function?
Synopsis: At the top of the page, I've set up a bunch of things to include, headers,body,footer, and some variables unique to the page in question.. (such as if the page is the contact page or if it's the homepage)
At the top of this page, is an IF statement, basically asking if we need to get mySQL database credentials or not.
I'd like to turn this IF statement into a function.
The IF statement: (I still haven't tested to see if it'll work or not)
$yesDBconnect = REQUIRE_ONCE ('{GURL}/include/mysql_con.php');
$DBconnect = FALSE;
$yesDBconnect = REQUIRE_ONCE ('{GURL}/include/mysql_con.php');
if ($DBconnect == TRUE)
$yesDBconnect
endif;
I'd like it to be a function like, connect_to(YES); or connect_to(NO); I'm pretty new to this, I've got my variables down, but other then th开发者_JS百科at I'm slacking. :P
Thanks in advance!
You ought to use require_once
(lowercase), which is a language construct and doesn't need its argument in parenthesis.
When using alternate control structures, you should place a colon (:
) at the end of your condition.
If using what you suggest, make sure the mysql_con.php
file uses...
return array(
'host' => 'localhost',
...
);
...or similar.
精彩评论