我有一個php腳本,它返回一些帶有特殊字符的值,特別是單引號(')和'at符號'(@)。包含這些字符的值不會插入到數據庫中。我在MySQL數據庫中看到了一篇文章(http://stackoverflow.com/questions/2584066/php-how-to-insert-special-characters-into-a-database)。 我的問題是如何在Postgresql數據庫中完成。在Postgresql數據庫中插入特殊字符
請參見下面的PHP代碼:
<?php
require 'table.php';
// Opens a connection to a PostgresSQL server
$connection = pg_connect("dbname=postgis user=postgres password=local");
// Execute query
foreach ($xml->item as $entry){
$georss = $entry->children($namespaces['georss']);
list($lat, $lng) = explode(' ', (string)$georss->point);
$query = "INSERT INTO geognews(title, link, author, latitude, longitude) VALUES ('" . $entry->title . "', '" . $entry->link . "', '" . $entry->children($namespaces['dc'])->creator . "', '" . $lat . "', '" . $lng . "')";
$result = pg_query($query);
printf ("These values are inserted into the database - %s %s %s", $entry->title, $entry->link, $entry->children($namespaces['dc'])->creator, $lat, $lng);
}
pg_close();
?>