Getting PDO database connection in OSSN component - what's the proper way?

eric redegeld Posted in Component Development 1 month ago

If using OSSN:
OSSN version: 8...
Website URL (optional): justbsocial.eu

If facing any bug:
PHP Version : 8.2
Error Log if any: none
Browser: all
OS (Window/Linux/Android/iOS/Mac):

I'm building a component that needs direct database access for bulk operations. I can't figure out how to properly get database credentials.
The Problem
OssnDatabase->execute() doesn't work for INSERTs:
php$db = new OssnDatabase;
$result = $db->execute("INSERT INTO ossn_entities (...)");
// Returns false, no error message
Database constants are undefined:
phprequire_once(ossn_route()->configs . 'ossn.config.db.php');
$host = OSSN_DATABASE_SERVER;
// Error: Undefined constant "OSSN_DATABASE_SERVER"
Hardcoded credentials work (but not suitable for distribution):
php$pdo = new PDO("mysql:host=localhost;dbname=mydb", "user", "pass");
// Works perfectly!
My Questions

What's the official/proper way to get a PDO connection in an OSSN component?
Is there a method to access the internal PDO object from OssnDatabase?
Why don't the config constants work when required from a component view file?

Context

Component runs from admin settings page
Need to INSERT thousands of entities (bulk tagging system)
Standard OSSN entity functions are too slow for bulk operations
Manual SQL works fine - just need proper credential access

Any pointers to documentation or example code would be great!

Replies
Dutch Eric redegeld Replied 1 month ago

where can i find the stored user setting in database for there langauge choice

Dutch Eric redegeld Replied 1 month ago

Thank you!!!!!!

Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions