error when consulting a table with name something $ something

0

I have a query similar to this:

select * from nombre$tabla where valor = 1;

If I run this on my bd engine it works (Oracle), but when I run this from PHP it does not return records, the code in php is sending it like this:

$query = "select * from nombre\$tabla where valor = 1"

$conection  = self::DbOracle();        
$sql = $conection->prepare($query);          
$sql->execute();        
$resultado = $sql->fetchAll();

Has anyone done something similar? Obviously I can not change the name of the table

PS: I already try to pass the name of the table as a variable concatenating the string and it does not return values either

    
asked by Javier 17.05.2017 в 00:24
source

1 answer

0

You can also use your query in the following way to pass the table name in variable:

$username = 'xxx';
$password = 'xxx';

try {
   $conn = new PDO($dsn, $username, $password);
   echo "<h2>Base de Datos CODINGGROUND Conectada<h2>";
}catch(PDOException $e){
   echo "<h1>" . $e->getMessage() . "</h1>";
}
$mysql_tb = 'users';

$sql ="SELECT * FROM '{$mysql_tb}'";

$stmt = $conn->prepare($sql);
$stmt->execute();
    
answered by 17.05.2017 в 00:51