P
P
parger2019-10-12 21:10:15
PHP
parger, 2019-10-12 21:10:15

After connecting 2 db, the code (RedBean) does not work?

I connect 2 DB

<?php
require 'engine/lib/rb.php';
R::setup('mysql:host=localhost;dbname=sait',
  'root',''); //База данных сайта
R::addDatabase('DB1','mysql:host=localhost;dbname=server',
    'root','',$server);	//База данных сервера #1
R::selectDatabase('DB1');
R::selectDatabase('default');
if(!R::testconnection())
{
        exit ('Нет соединения с базой данных');
}
session_start();
?>

Code where you need to use 2 database
<?php
                  R::selectDatabase('DB1');
                  $users = R::getAll( 'SELECT * FROM accounts WHERE `online` >=0 AND `admin` >= 1' );
                  foreach ($users as $user)
                  {
                    $id = $user['id'];
                    $user = R::load('accounts', $id);
                    echo('<a href="nickname.php?iddb='.$user[id].'">');
                      echo('<li type="1">[LVL '.$user[admin].'] '.$user[Name].'(ONLINE: '.$user[online].')</li>');
                    echo('</a>');
                    var_dump($users);
                  }
                  ?>

But when used, nothing happens. Used var_dump($users); displays all values ​​from the database calmly, but does not work in the code

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitsliputsli, 2019-10-12
@Vitsliputsli

Turn on error display or read the logs. where did this $server variable come from?

$user[id]
$user[admin]
$user[Name]
what's with the weird syntax for accessing an array element?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question