I have a very dynamic scenario that requires met to store queries as a string in the database, the problem I have is that the following have resulted in a syntax error where the variables are creating a MySQL error with the error showing the variable name and not the value. The SQL is pulled from the database then set up like so:
$database1_sql= $DB_con2->prepare("$sql1");
$database1_sql->execute();
I have tried the following all resulting in the same issue, and I am stumped:
`
select columns
FROM '.$database_1_old.'.'.$table1.' as dsp
or
FROM '".$database_1_old."'.'".$table1."' as dsp
or
FROM $database_1_old.$table1
or
FROM '" . $database_1_old . "'.'" . $table1 . "'
`
I have also tried using the eval function thinking that might get around the errors and use the variables as intended, but I get an t string error in the first few characters in my column list.
I have used variables in queries before, but not in this manner where the query is a row from a database.
What am I missing?
Thanks!