@tracyjs
better make a plugin.
Check systemconfiguration:
OnWebPageInit
OnWebAuthentication
OnManagerAuthentication
OnModFormRender
put this in you plugin text:
function ConnectMy()
{
global $db;
$db = mysql_connect("localhost", "username", "password") or die("Can't connect to database (MySQL).");
}
from that moment on you can user
ConnectMy();
on every snippet or module (even other plugin) to connect to your db.
expand the plugin with some other features and you can use that also.
i created a complete class and can use it from wherever.
i even connect to different dbs
function ConnectMS()
{
global $dbm;
$dbm = mssql_connect("myserver70", "user", "pw") or die("Can't connect to database (MS-SQL).");
}
function ConnectMy()
{
global $db;
$db = mysql_connect("localhost", "user", "pw") or die("Can't connect to database (MySQL).");
}
function ConnectMy2()
{
global $db;
$db = mysql_connect("localhost", "root", "pw") or die("Can't connect to database (MySQL).");
}
function ConnectOra()
{
global $db;
$db = oci_connect("user", "pw", "//IP") or die("Can't connect to database (Oracle).");
$sql_timestamp_set = "ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'DD-MM-YYYY HH24:MI:SS'";
$do = oci_parse($db, $sql_timestamp_set);
oci_execute($do);
$sql_date_set = "ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MM-YYYY HH24:MI:SS'";
$do = oci_parse($db, $sql_date_set);
oci_execute($do);
$sql_schema = "alter session set current_schema = schemaname";
$do = oci_parse($db, $sql_schema);
oci_execute($do);
return $db;
}