Change database connection

Hello,

I am trying to change MySQL database connection.

Primary I have database: my_default_db

I want to set new database for each customer separately.

I tried many things, but not succedded.

I stored all data of all customers in one database, named: all_clients where I have all data of separated database.

Here is the code which I tried to implement:

$check_sql = “SELECT drive, server, user, password, database, persistent, encoding”
. " FROM PT_Narocniki_firma"
. " WHERE Naziv = ‘" . {Podjetje} . "’";
sc_lookup(rs, $check_sql);

$drive = {rs[0][0]};
$server = {rs[0][1]};
$user = {rs[0][2]};
$password = {rs[0][3]};
$database = {rs[0][4]};
$persistent = {rs[0][5]};
$encoding = {rs[0][6]};

$arr_conn = array();

$arr_conn[‘drive’] = $drive;
$arr_conn[‘server’] = $server;
$arr_conn[‘user’] = $user;
$arr_conn[‘password’] = $password;
$arr_conn[‘database’] = $database;
$arr_conn[‘persistent’] = $persistent;
$arr_conn[‘encoding’] = $encoding;

sc_connection_edit(“DATABASE”, $arr_conn);


After this connection DATABASE is still connected to “my_default_db”. It doesn’t change to $database. Why?

Thank you for your answers!

Well, the most obvious question. What returns exactly {rs}? Can you print_r({rs}) and paste here? Wich event of with type of app is this code executed?

OKAY!
I have solution. I do not know why, but I have to change filed name “database” to “base”. Now it is working.

So, code is basicaly the same. I changed just this row:

$check_sql = “SELECT drive, server, user, password, database, persistent, encoding”

to this

$check_sql = “SELECT drive, server, user, password, base, persistent, encoding”

In some database systems the word database is a restricted word.