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

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

I thought this was the most practical and radical solution. With the minimal and ineffective fix in the kernel, I implemented the following

\Database\SQLSRV\Builder.php
I included the following code in the getFullName method.

\Database\SQLSRV\Builder.php
getFullName() metoduna şu kodu dahil ettim.

PHP Code:
private function getFullName(string $table): string
    
{
        $alias '';
        
        
if (strpos($table' ') !== false) {
            $alias explode(' '$table);
            $table array_shift($alias);
            $alias ' ' implode(' '$alias);
        }
         //Multiple Db Table Connect
        if(str_contains($table,'"dbo"'))
        {
            return $table;
        }
         //Multiple Db Table Connect
        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);
    


PHP Code:
$this->db = \Config\Database::connect('default');
 
$this->db->table('LOG_DB.dbo.adminLogs')->select('*')->get()->getRow();
 echo 
$this->db->getLastQuery();
 die();
//TSQL : SELECT * FROM "LOG_DB"."dbo"."adminLogs" 
Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB