Datatables with multiple tables from multiple databases

Datatables with multiple tables from multiple databases

ECEGROUPEECEGROUPE Posts: 78Questions: 29Answers: 1
edited August 2022 in General

Currently, i use one datatables to work with differents tables from a same database (with left join).

Is it possible to use one datatables with fields from differents tables from differents database ?

In config.php, i have set up $sql_details and $sql_details2 for the connection to the 2 databases.
In bootstrap.php, i have set up $db = new Database( $sql_details ); and $db2 = new Database( $sql_details2 );

How do i set up staff.php ?

Editor::inst( $db, 'mytable' )
    ->fields(
Field::inst(
Field::inst( 'mytable.name' ), 
 )          
    ->debug(true)
    ->process( $_POST )
    ->json();

this work for one database but i can't use Editor::inst( $db2, 'mytable2' ) for the second database, how i m suppose to access the second database ?

Thx for your answer :)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Not with two different database connections. Editor can only operate with a single connection.

    However, if the user you are using to connect to the database to, has access rights to both databases, then that would work using the syntax 'myDb1.table1.field1' (etc).

    Allan

  • ECEGROUPEECEGROUPE Posts: 78Questions: 29Answers: 1
    edited August 2022

    That's the case, the user have access right to both databases.

    How to use the syntax 'myDb1.table1.field1', can you give me an exemple pls ?

  • ECEGROUPEECEGROUPE Posts: 78Questions: 29Answers: 1
    edited August 2022

    i understand i have to use a single connection without specifying the database so i can connect to both database with $sql_details. (that work)

    I have set up all my fields with the syntax myDb1.mytable.field BUT when i use the editor, i have to specify a database and a table Editor::inst( $db, 'myDb1.mytable' ) so how i m suppose to acces an other table / another db if i have to do this ?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited September 2022 Answer ✓

    With a join. You are reading from one table on a specific db, and then joining it to another from another db I presume?

    Allan

  • ECEGROUPEECEGROUPE Posts: 78Questions: 29Answers: 1

    It work, thank you for the answer :)

Sign In or Register to comment.