【发布时间】:2012-03-24 06:59:27
【问题描述】:
我有一个 php 脚本,它返回一些带有特殊字符的值,尤其是单引号 (') 和 'at 符号'(@)。包含这些字符的值不会插入到数据库中。我在 (http://stackoverflow.com/questions/2584066/php-how-to-insert-special-characters-into-a-database) 上看到了一篇在 mysql 数据库上执行此操作的帖子。 那么我的问题是如何在 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();
?>
【问题讨论】:
标签: php postgresql insert special-characters