Home > Backend Development > PHP Tutorial > php数据库连接错误

php数据库连接错误

WBOY
Release: 2016-06-23 13:46:22
Original
1046 people have browsed it

有代码如下:

$catid=intval($_REQUEST['catid']);
$sql_store = 'SELECT * FROM ecm_gcategory  Where cate_id=$catid ORDER BY cate_id';
$my_category= DB::fetch_all($sql_store);

运行报如下错误:
SELECT * FROM ecm_gcategory Where cate_id=$catid ORDER BY cate_id


怎么解决哟?请高人指点!


回复讨论(解决方案)

报错如下:
1054) Unknown column '$catid' in 'where clause'
SELECT * FROM ecm_gcategory Where cate_id=$catid ORDER BY cate_id

$sql_store = "SELECT * FROM ecm_gcategory  Where cate_id=$catid ORDER BY cate_id";
双引号!

单引号里面的变量不能被解析,需用双引号括起来。或者改成下面这样:
$sql_store = 'SELECT * FROM ecm_gcategory  Where cate_id='.$catid.' ORDER BY cate_id';

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template