I’m following this guide in the EE wiki as I need to do some custom queries (outside the query module).
http://expressionengine.com/wiki/SQL_query_with_pure_PHP/
I’m new to php and so wondering what advice people having in best practices for handling the code for the database connection and close.
Do I have to type the first five lines of this example code in all my custom php pages or is there an easier way to include this information as a global variable.
<?php global $PREFS;
$db = mysql_connect( // Handle the connection to the database.
$PREFS->core_ini['db_hostname'], // hostname,
$PREFS->core_ini['db_username'], // username and
$PREFS->core_ini['db_password']); // password are automatically pulled
mysql_select_db($PREFS->core_ini['db_name']); // from EE's config.php
Looking for good advice on best practices.