I’m a bit confused with this: can I use PHP variables in a pg query?
$conn = pg_pconnect("...");
$a = 1
$b = array ("....")
$c = array ("....")
$d = array ("....")
$i = $a
$ct = "CREATE TABLE $a
(
$b[$i] bigint,
$c[$i] bigint,
$d[$i] bigint
)";
pg_query($conn, $ct);
$result = pg_query($conn, $ct);
if ($result) {$a = $a++}
Will this be able to create 10 tables if I loop this 10 times? Thanks!
If you want to prepare your strings to to be suitable identifiers for PostgreSQL (mixed case? reserved words?) and safeguard against SQL injection at the same time, throw in a
pg_escape_identifier():Unless, of course, your identifiers are prepared already.