执行查询时收到以下错误消息:
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax near '://www.website.com.br/Manual_01/Realm/1980-1988/R7678.htm' na linha 1: SELECT (field_data_field_url.entity_id) FROM field_data_field_url WHERE field_data_field_url.field_url_value = http//www.website.com.br/Manual_01/Realm/1980-1988/R7678.htm ; Array ( ) em _xmlrpc_troca()
这是我的Drupal模块的功能:
$query = db_query("SELECT (field_data_field_url.entity_id) FROM field_data_field_url WHERE field_data_field_url.field_url_value = $url ");
foreach ($query as $record) {
echo $record->entity_id;
}
return $record;
如果我将'$ url'包裹起来'',那么它可以工作:
$query = db_query("SELECT (field_data_field_url.entity_id) FROM field_data_field_url WHERE field_data_field_url.field_url_value = '$url' ");
但我在xmlrpc响应时收到错误,因为它在发送响应时发回''并且我得到错误。这个响应带有正确的数据,但它没用,因为我无法解析它。 有人知道如何解决它?
编辑:
响应是这样的:
body: '30254<?xml version="1.0"?>\n\n<methodResponse>\n <params>\n <param>\n <value><struct>\n <member><name>entity_id</name><value><string>30254</string></value></member>\n</struct></value>\n </param>\n </params>\n</methodResponse>\n\n'
最后'30254
和'
是问题所在。我收到此错误消息:
ExpatError: not well-formed (invalid token): line 1, column 5
答案 0 :(得分:0)
您应该尝试使用db_query参数。
<?php $query = db_query('SELECT (field_data_field_url.entity_id) FROM field_data_field_url WHERE field_data_field_url.field_url_value = :url', array(':url' => $url)); ?>
您也可以尝试使用db_select()函数。
<?php
$select = db_select('field_data_field_url', 'fdfu'); // fdfu is an alias
$select->fields('fdfu', array('entity_id'));
$select->condition('field_url_value', $url);
$query = $select->execute();
foreach($query as $result) {
echo $record->entity_id;
}
?>