PDO和IS NOT NULL函数 [英] PDO and IS NOT NULL Function

查看:50
本文介绍了PDO和IS NOT NULL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PDO的新手,我想知道是否存在与mysql语句等效的语句,该语句检查参数是否不为null,例如:

I am new to PDO and I was wondering if there was an equivalent to a mysql statement that checks if a parameter is not null such as:

SELECT * FROM table
WHERE param IS NOT NULL

我尝试过:

$pdo->prepare('SELECT * FROM ' . $tablename . ' WHERE ' . $field . ' = :' . $field . 'AND param IS NOT NULL');

没有成功. 我也在网上浏览了一下,但没有找到任何相关信息,有人可以帮忙吗?

without any success. I also looked on the web, but did not find anything relevan, can anyone help please ?

推荐答案

您可以在pdo中使用可以直接在mysql中使用的任何查询,但是您这样做的方式却使首先使用PDO的目的遭到了挫败,应将查询的短语设置为

You can use any query in pdo that you could use in mysql directly but your way of doing it is defeating the purpose of using PDO in the first place, you should phrase the query as

$q = $pdo->prepare("SELECT * FROM $tablename WHERE field = :field AND param IS NOT NULL");
$q->execute(array('field' => $field));

这篇关于PDO和IS NOT NULL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆