I'm building an application using CodeIgniter. currently trying to find a way to retrieve data from a 2nd database that contains tables with names that contain special characters and spaces.

I'm trying to retrieve data in my model like this :

```
 public function getCommandeData($username= null)
{
    $this->legacy_db = $this->load->database('OtherDB', true);
    $bdd ='[SS$DP - Order]';
    if($username) {
        $sql = "SELECT top 5 FROM" + $bdd+"  WHERE id = ?";
        $query = $this->legacy_db->query($sql, array($username));
        return $query->result_array();
    }

    $sql = 'SELECT top 5 FROM [SS$DP - Order]';
    $query = $this->legacy_db->query($sql);
    return $query->result_array();
}

```

but I'm getting this error:

> 
> [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Syntaxe incorrect vers le mot clé 'FROM'. SELECT top 5 FROM [SS$DP - Order]
> 
> 
> 

Here where I defined the alternative connection to this database:

```
$db['OtherDB'] = array(
'dsn'   => '',
'hostname' => '192.168.14.100',
 'port' => '1433',
'username' => 'StockAgent',
'password' => 'StockAgent',
'database' => 'SVC',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

```

);

Can anyone tell me what's the problem and how to fix it ?

**EDIT2**

After adding the space between **From** and the **$bdd**

> 
> Severity: Warning
> 
> 
> 

Message: A non-numeric value encountered

pointing this line :

```
 $sql = "SELECT * FROM " + $bdd;

```

**EDIT 2** 

I figured Out that **$bdd** is a string so it's better to use concatenate `.=$bdd` instead of `+$bdd`

So my function become like this :

```
   public function getCommandeData($username= null)
{
    $this->legacy_db = $this->load->database('OtherDB', true);
    $bdd ='[SS$DP - Order]';

    /*($username) {
        $sql = "SELECT top 5 FROM " +$bdd;/* " WHERE id = ?"
        $query = $this->legacy_db->query($sql, array($username));
        return $query->result_array();
    }*/

    $sql = "SELECT top 2 FROM " ;
    $sql.=" ";
    $sql.=$bdd;
    $query = $this->legacy_db->query($sql);
    return $query->result_array();

}

```

when I try to retrieve all the date by using `select *` I'm getting this error: 

> 
> Memory limit of 10240 KB exceeded for buffered query SELECT \* FROM [SS$DP - Order]
> 
> 
> 

But When I limit the size by doing top 50 I'm getting this 

> 
> [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Syntaxe incorrecte vers le mot clé 'FROM'. SELECT top 50 FROM [SS$DP - Order]
> 
> 
>