Connect to DB using apache setting.

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
DevMatGod
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Sep 29, 2017 2:06 pm

Connect to DB using apache setting.

Post by DevMatGod » Mon Feb 05, 2018 8:10 pm

Hello, I'm programming a site with some restrictions. One of them is that I am forbidden to place information for the connection to the database in my code.

To be more precise, the instruction tell me to use apache's setting. Witch is already configured to connect to the database.

As a matter of fact, I can create a connection with the following code.

Code: Select all

<?php
$link = mysqli_connect()
    or die("Impossible de se connecter : " . mysqli_error());
echo 'Connexion réussie';
mysql_close($link);
?>

Unfortunately I do not know how to implement this to joomla.

Is there a solution to my problem?


Thank you in advance
Last edited by toivo on Mon Feb 05, 2018 9:43 pm, edited 1 time in total.
Reason: mod note: moved to 3.x Coding

gws
Joomla! Champion
Joomla! Champion
Posts: 5950
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: Connect to DB using apache setting.

Post by gws » Tue Feb 06, 2018 11:24 am

As the db is the core to joomla and every component etc uses the inbuilt db connector I guess what you want is not possible without extensive customizing of joomla and then upgrading would be a problem.

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17439
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Connect to DB using apache setting.

Post by toivo » Tue Feb 06, 2018 11:51 am

DevmatGod wrote:To be more precise, the instruction tell me to use apache's setting. Witch is already configured to connect to the database.
The database functions are part of PHP, not Apache. Joomla uses its own database classes and methods for connecting to the MySQL database server and your code can just utilise them, without any connection details embedded in the code, assuming that your extension accesses the Joomla database.

On the other hand, if you want to connect to an external database, in other words, use Joomla database classes and methods to connect to a non-Joomla database, the following tutorial has all the details:
https://docs.joomla.org/Connecting_to_a ... l_database

Your code could read the credentials from a MySQL table or an .ini file so that none of those details have to be hard coded as part of your functions. Even better, if you are writing a Joomla component, add the database details into the extension as component parameters, to be filled in from Options by the Super User after the component has been installed.
Toivo Talikka, Global Moderator


Locked

Return to “Joomla! 3.x Coding”