gpt4 book ai didi

php - php sql 语法错误或访问冲突

转载 作者:行者123 更新时间:2023-11-29 21:05:15 24 4
gpt4 key购买 nike

我已经在我的代码中添加了这个sql,

function devenir_client_dataforform() {
$type = $_POST['clientType'];
//$produitname = $_POST['produitname'];
$produitnid = $_POST['produitnid'];
$query = db_select('node', 'n');

$query->leftjoin('field_data_field_description_col_1', 'img', 'img.entity_id = n.nid');
$query->leftjoin('field_data_field_pdf_file_image', 'pdf', 'pdf.entity_id = n.nid');
$query->leftjoin('taxonomy_term_data', 't', 't.tid ='.$type);



$query->condition('n.nid', $produitnid, '=')
//->condition('t.tid', $type, '=')
->fields('n', array('title'))
->fields('t', array('name'))
->fields('pdf', array('field_pdf_file_image_fid'))
->fields('img', array('field_description_col_1_value'));

$result = $query->execute();
foreach ($result as $record) {
if(!empty($record->field_description_col_1_value)) {
$fid = $record->field_description_col_1_value;
$produitname = $record->title;
$pdf = $record->field_pdf_file_image_fid;
$tp = $record->name;

}
}
$file = file_load($pdf);
$uri = $file->uri;

$path = file_create_url($uri);
//$uri = image_style_path( $path);
$items[] = array(
"type" => $tp ,
"produitname" => $produitname,
"produitnid" => $produitnid,
"image" => $fid,
"pdf" => $path,
"typeid" => $type
);
return $items;
}

但最后一步出现错误

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (n.nid = NULL)' at line 4: SELECT n.title AS title, t.name AS name, pdf.field_pdf_file_image_fid AS field_pdf_file_image_fid, img.field_description_col_1_value AS field_description_col_1_value FROM {node} n LEFT OUTER JOIN {field_data_field_description_col_1} img ON img.entity_id = n.nid LEFT OUTER JOIN {field_data_field_pdf_file_image} pdf ON pdf.entity_id = n.nid LEFT OUTER JOIN {taxonomy_term_data} t ON t.tid = WHERE (n.nid = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => ) in devenir_client_dataforform() (line 189 of /home/dotit_bh/bh-website.dotit.mobi/sites/all/modules/devenir_client/devenir_client.module).

enter image description here

最佳答案

这部分SQL查询错误:

 WHERE (n.nid = NULL)

正确的 SQL 查询:

WHERE (n.nid is NULL)

你应该重写你的脚本:

$nid_operator = ($produitnid ? '=' : 'is');
$query->condition('n.nid', $produitnid, $nid_operator)
//->condition('t.tid', $type, '=')
->fields('n', array('title'))
->fields('t', array('name'))
->fields('pdf', array('field_pdf_file_image_fid'))
->fields('img', array('field_description_col_1_value'));

关于php - php sql 语法错误或访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36877702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com