Hãy thử một cái gì đó như thế này. Lưu ý việc sử dụng pg_query_params()
thay vì pg_query()
để chèn để bảo vệ khỏi việc đưa vào SQL.
<?php
$pra = "SELECT * FROM people";
$decks = pg_query($connection, $pra);
if(!$decks){
$sql = "CREATE TABLE people(
mom INT PRIMARY KEY NOT NULL,
non TEXT NOT NULL,
ooo INT NOT NULL,
ppp INT NOT NULL,
aqqq TEXT,
pq TEXT
)";
$rcon = pg_query($connection, $sql);
if(!$rcon){
echo pg_last_error($connection);
} else {
echo "Database table created"; //success confirmation
}
}
$val_array = array($mom, $non, $ooo, $ppp, $aqqq, $pq);
var_dump($val_array);
$ins = " INSERT INTO people (mom, non, ooo, ppp, aqqq, pq)
VALUES($1, $2, $3, $4, $5, $6)";
$rcon =pg_query_params($connection, $ins, $val_array);
if(!$rcon){
echo pg_last_error($connection);
} else {
echo "Record added to database"; //success confirmation
}
?>