Hi, how do I connect to a MySQL database using PHP so it does not need to be set in the MRT file? The file moves from local to production and each environment has different usernames and passwords.
I am including my database connection php at the top of the page which includes (actual data has been changed):
// Database Connection
$dbtype = "mysql";
$dbhost = "localhost";
$dbname = "database";
$dbuser = "username";
$dbpass = "password";
mysql_connect($dbhost,$dbuser,$dbpass);
@mysql_select_db($dbname) or die( "Error #1001.");
Can I link to this connection? or do i have to specify it in the sti_get_connection_string function? I tried that too like this:
function sti_get_connection_string($connection_type, $connection_string)
{
switch ($connection_type)
{
case "StiSqlDatabase": return "Data Source=SERVER\SQLEXPRESS;Initial Catalog=master;Integrated Security=True";
case "StiMySqlDatabase": return "Server=".$dbhost.";Database=".$dbname.";Port=3306;User=".$dbuser.";Password=".$dbpass.";"
case "StiOdbcDatabase": return "DSN=MS Access Database;DBQ=D:\NWIND.MDB;DefaultDir=D:;DriverId=281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;UID=admin;";
case "StiPostgreSQLDatabase": return "Server=localhost;Database=db_name;Port=5432;User=postgres;Password=postgres;";
}
return $connection_string;
}
I'm assuming I have to link to the connection somehow from the MRT file but am unsure how.
Thanks
Connection to MySQL database from PHP
Connection to MySQL database from PHP
Hello,
You can use sti_get_connection_string function for changing connection string. In the indicated example you have everything is done correctly.
Thank you.
You can use sti_get_connection_string function for changing connection string. In the indicated example you have everything is done correctly.
Thank you.
Connection to MySQL database from PHP
Hi, I didn't understand. I have the connection set in my function. I only want to allow MySQL connections to the database so i modified the function to look like this:
function sti_get_connection_string()
{
return "Server=".$dbhost.";Database=".$dbname.";Port=3306;User=".$dbuser.";Password=".$dbpass.";";
}
Where do I run sti_get_connection_string()? In the PHP or in the MRT doc? In my MRT file, i have a connection with the connection string blank.
Thanks
function sti_get_connection_string()
{
return "Server=".$dbhost.";Database=".$dbname.";Port=3306;User=".$dbuser.";Password=".$dbpass.";";
}
Where do I run sti_get_connection_string()? In the PHP or in the MRT doc? In my MRT file, i have a connection with the connection string blank.
Thanks
Connection to MySQL database from PHP
Hello,
This function, which is located in the 'index.php' file, will be called automatically when report generator requesting data.
Thank you.
This function, which is located in the 'index.php' file, will be called automatically when report generator requesting data.
Thank you.
Connection to MySQL database from PHP
Silly me, I forgot to declare my variables as Global in the function.
Thanks
Thanks