deple Posted March 18 Posted March 18 Hello, how can I extract data from an external database to a table? ($table) Â
teraßyte Posted March 18 Posted March 18 You need to establish a connection to the external/remote database you want to use, and then run the queries with the usual framework code to retrieve/display the data:  The first codebox shows an example of how to start an external database connection. deple 1
deple Posted March 18 Author Posted March 18 I have connect, but how i must use $table? Â $connection = \IPS\Db::i( 'external', array( Â Â Â 'sql_host'Â Â Â Â Â Â => 'localhost', Â Â Â 'sql_user'Â Â Â Â Â Â => 'username', Â Â Â 'sql_pass'Â Â Â Â Â Â => 'password', Â Â Â 'sql_database'Â Â Â => 'database_name', Â Â Â 'sql_port'Â Â Â Â Â Â => 3306, Â Â Â 'sql_socket'Â Â Â => '/var/lib/mysql.sock', Â Â Â 'sql_utf8mb4'Â Â Â => true, ) ); $table = new IPS\Helpers\Table\Db( 'core_test', 'app=core&module=test§ion=test1', NULL, NULL, $connection); Â
Daniel F Posted March 19 Posted March 19 What’s the question? What are you trying to achieve/what’s the issue you’ve run into?  what’s happening when you try to show the table? without any further code i would guess: - your passed url is wrong - You‘re missing the table templates G17 Media 1
deple Posted March 19 Author Posted March 19 (edited) Error: Class name must be a valid object or a string (0) #0/public_html/system/Theme/Dev/Template.php(171): IPS\Theme\theme_core_front_tables_rows(Object(IPS\Helpers\Table\Db), Array, Array) #1 /public_html/system/Theme/Theme.php(4625) : eval()'d code(513): IPS\Theme\Dev\_Template->__call('rows', Array) #2 /public_html/system/Theme/Dev/Template.php(171): IPS\Theme\theme_core_front_tables_table(Object(IPS\Helpers\Table\Db), Array, Array, NULL, false) #3 /public_html/system/Helpers/Table/Table.php(579): IPS\Theme\Dev\_Template->__call('table', Array) #4 /public_html/system/Theme/Theme.php(4625) : eval()'d code(422): IPS\Helpers\Table\_Table->__toString() #5 /public_html/system/Theme/Dev/Template.php(171): IPS\Theme\theme_core_front_global_globalTemplate(' - Invision Com...', Object(IPS\Helpers\Table\Db), Array) #6 /public_html/system/Dispatcher/Dispatcher.php(173): IPS\Theme\Dev\_Template->__call('globalTemplate', Array) #7 /public_html/system/Dispatcher/Standard.php(113): IPS\_Dispatcher->finish() #8 /public_html/system/Dispatcher/Front.php(558): IPS\Dispatcher\_Standard->finish() #9 /public_html/system/Dispatcher/Dispatcher.php(155): IPS\Dispatcher\_Front->finish() #10 /public_html/index.php(13): IPS\_Dispatcher->run() #11 {main} I probably have an incorrectly connected external database in $table  $connection = \IPS\Db::i( 'external', array( 'sql_host' => 'localhost', 'sql_user' => 'username', 'sql_pass' => 'password', 'sql_database' => 'database_name', 'sql_port' => 3306, 'sql_socket' => '/var/lib/mysql.sock', 'sql_utf8mb4' => true, ) ); $database = \IPS\Db::i('external'); $tablee = 'table_db'; $baseUrl = \IPS\Http\Url::internal( 'app=test&module=test&controller=test' ); $table = new \IPS\Helpers\Table\Db($tablee, $baseUrl, NULL, NULL, $database); $table->include = array( 'id', 'id_name' ); \IPS\Output::i()->output = $table;  Edited March 19 by deple
Solution DawPi Posted March 19 Solution Posted March 19 (edited) Did you specify the $table->rowsTemplate value? 🙂 It's required for a front DB Helpers if I'm not wrong. Edited March 19 by DawPi G17 Media, teraßyte and deple 3
Recommended Posts