Hi everyone.
For the component I am working on I need to connect to an external database to import records from a file that I have received. I'm using MYSQLI_OPT_LOCAL_INFILE to do this because there are lots of records and because I have used it successfully to import records to my own database.
Where I am struggling is making the connection to the other database using Joomla 5. I'm not sure if this is different than previous Joomla versions. I found some references and I adapted it to my code. Unfortunately, I am receiving this "Illegal offset type" error whenever I run the code.
Below is the code I am using in Joomla 5.0.2 / PHP 8.2. The error occurs on this line:
$db = Factory::getContainer()->get($params)
What am I missing when attempting getContainer?
Thanks in advance!
Michael
For the component I am working on I need to connect to an external database to import records from a file that I have received. I'm using MYSQLI_OPT_LOCAL_INFILE to do this because there are lots of records and because I have used it successfully to import records to my own database.
Where I am struggling is making the connection to the other database using Joomla 5. I'm not sure if this is different than previous Joomla versions. I found some references and I adapted it to my code. Unfortunately, I am receiving this "Illegal offset type" error whenever I run the code.
Below is the code I am using in Joomla 5.0.2 / PHP 8.2. The error occurs on this line:
$db = Factory::getContainer()->get($params)
Code:
$sql = "...my query...";$params = array();// Set $params values$params = array(); $params['driver'] = 'mysqli'; $params['host'] = 'localhost'; $params['user'] = 'myuser; $params['password'] = 'mypassword'; $params['database'] = 'mydb';$params['prefix'] = 'llssdc';// Get connection$db = Factory::getContainer()->get($params);$connection = $db->getConnection();// Set mysqli_optionsmysqli_options($connection, MYSQLI_OPT_LOCAL_INFILE, true);$sql = $db->replacePrefix($sql);// Execute query$connection->execute($sql);
Thanks in advance!
Michael
Statistics: Posted by mb87 — Tue Feb 13, 2024 2:52 am