首页 > 解决方案 > PHP - sql字符串之间的空格

问题描述

当我运行我的代码时,我收到此错误:

WordPress-databaseerror 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在“fromwpiy_veosoft_crm_customerwhere Id = 957”附近使用正确的语法

 $wpdb->prepare("select * from".$this->tables->tableCustomer()."where Id = %d", $data_id), ARRAY_A

我试图在 from 和 " 和 where 之前创建空格,但是当我这样做时,它没有意识到它是一个 sql qurrie。

我希望它看起来像这样并且可以工作,但是我已经尝试过了,但我没有

$wpdb->prepare("select * from ".$this->tables->tableCustomer()." where Id = %d", $data_id), ARRAY_A

标签: phpsql

解决方案


试试下面的代码:

$data_id = 957;
$prepare = $wpdb->prepare("SELECT * FROM " . $this->tables->tableCustomer() . " WHERE Id = %d", $data_id);
$wpdb->get_results($prepare, ARRAY_A);

希望能帮到你。


推荐阅读