CB System Params - DB Credentials

5 years 9 months ago #305947 by MMDoege
CB System Params - DB Credentials was created by MMDoege
Hello,

Is there a way to retrieve credentials of current DB (server, DB name, DB user, DB pw) as a CB substitution?
Would be great for auto actions with eg. PHP code to open DB to fire SQL statements.

Thanks.

Please Log in to join the conversation.

5 years 9 months ago #305955 by krileon
Replied by krileon on topic CB System Params - DB Credentials

Is there a way to retrieve credentials of current DB (server, DB name, DB user, DB pw) as a CB substitution?

No, that'd be a security vulnerability.

Would be great for auto actions with eg. PHP code to open DB to fire SQL statements.

You don't need those credentials to execute SQL in PHP. Use Joomla or CBs database API for that. See Joomlas documentation regarding Joomlas API.

docs.joomla.org/Accessing_the_database_using_JDatabase

For CBs API you need to set a global then you'd use the global as you would a JDatabase object. Example as follows.

global $_CB_database;

$query		=	"SELECT COUNT(*)"
			.	"\n FROM " . $_CB_database->NameQuote( 'TABLE_HERE' )
			.	"\n WHERE " . $_CB_database->NameQuote( 'COLUMN_HERE' ) . " = " . $_CB_database->Quote( 'VALUE_HERE' );
$_CB_database->setQuery( $query );
$exists		=	$_CB_database->loadResult();


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

5 years 9 months ago #306021 by MMDoege
Replied by MMDoege on topic CB System Params - DB Credentials
Thank you for your instant reply.

We're used to dev. code for CB Auto Action with PHP on server directly and then to transfer and adapt it to CB Auto Action action requirements.
This is straightforward and works well.

The Joomla code suggested by Joomla returned just a HTTP 500 server error.
Is code mentioned in the Joomla doc not intended to be used as a PHP program but inside Joomla?
Sorry for a stupid question, but may be you will give us a helping hand to sort this out.

Thanks.

Please Log in to join the conversation.

5 years 9 months ago #306039 by krileon
Replied by krileon on topic CB System Params - DB Credentials
Both Joomla and CB API can be used within the code action perfectly fine, but most of the classes are namespaced so you need to be sure to provide the full namespace path. Accessing CBs database API is just done using a global variable so don't need any namespace usage.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.192 seconds

Facebook Twitter LinkedIn