AND WHERE语法

时间:2016-04-05 03:41:30

标签: php mysql sql

此语句用于我的应用

$result = query("SELECT p.IdPhoto, p.device_token, p.IdUser FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto='%d'", $IdPhoto);

我还想存储device_token值,所以我添加了这一行。

$result = query("SELECT p.IdPhoto, p.device_token, p.IdUser FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto='%d' AND p.device_token='%d' ", $IdPhoto, $token);

我在应用程序中运行这行代码并且在调用此行时会退出,这很奇怪,因为第一行有关如何将device_token值存储在变量和IdPhoto中的任何想法?

php_error.log

[05-Apr-2016 06:21:19 Europe/Berlin] PHP Warning:  Missing argument 2 for stream(), called in /Applications/MAMP/htdocs/Hi2/index.php on line 44 and defined in /Applications/MAMP/htdocs/Hi2/api.php on line 123
[05-Apr-2016 06:21:19 Europe/Berlin] PHP Notice:  Undefined variable: token in /Applications/MAMP/htdocs/Hi2/api.php on line 145
[05-Apr-2016 06:21:19 Europe/Berlin] PHP Notice:  Undefined index: error in /Applications/MAMP/htdocs/Hi2/api.php on line 149

它说令牌是一个未定义的变量,这是我在方法中定义它的方式。

function stream($IdPhoto=0, $token) 

{

if ($IdPhoto==0) {

    ...

} else {

    $result = query("SELECT p.IdPhoto, p.device_token, p.IdUser FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto='%d' AND p.device_token='%d' ", $IdPhoto, $token);

}

声明$token变量的正确方法是什么?

0 个答案:

没有答案