Welcome Guest, Not a member yet? Register   Sign In
Connect to more than one database in a single connection
#5

(This post was last modified: 04-01-2024, 07:45 AM by mywebmanavgat.)

To summarize the result,
I will not use builder when I will use left join innerjoin etc. features between two databases. I will continue to use $db->query('TSQL'). I will not need too many such specific queries anyway.

$db->setDatabase('DB_NAME'); is enough for me to use builder for single table queries.

This way I can jump to different databases on the same server with a single database connection.

Changing the kernel and checking and reorganizing every update is time-costly for developers. That's why I didn't interfere with the kernel.

However, while developing the kernel, it could have been done that for each property that takes a table name, an additional parameter DBNAME and a check whether the scheme should be added to the table name or not would have made everything very easy.


The getFullName function in \Database\SQLSRV\Builder.php file could be like this.

PHP Code:
private function getFullName(string $table,$prefix=true): string
    
{
        $alias '';

        if (strpos($table' ') !== false) {
            $alias explode(' '$table);
            $table array_shift($alias);
            $alias ' ' implode(' '$alias);
        }
        //PrefixControl
        if($prefix == false)
        {
            return str_replace('"'''$table);
        }
       //PrefixControl
        if ($this->db->escapeChar === '"') {
            return '"' $this->db->getDatabase() . '"."' $this->db->schema '"."' str_replace('"'''$table) . '"' $alias;
        }

        return '[' $this->db->getDatabase() . '].[' $this->db->schema '].[' str_replace('"'''$table) . ']' str_replace('"'''$alias);
    
Reply


Messages In This Thread
RE: Connect to more than one database in a single connection - by mywebmanavgat - 04-01-2024, 07:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB