Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PDO查询在PHP中没有结果,但在phpmyadmin或mysql二进制文件中生成结果_Php_Mysql_Pdo - Fatal编程技术网

PDO查询在PHP中没有结果,但在phpmyadmin或mysql二进制文件中生成结果

PDO查询在PHP中没有结果,但在phpmyadmin或mysql二进制文件中生成结果,php,mysql,pdo,Php,Mysql,Pdo,我很难理解这一点 我有以下代码: $result=$db->query(" select `job_id`,`jobs`.`client` from `stores` left join `jobs` on `jobs`.`client`=`stores`.`id` where `stores`.`postcode`='BD5 8HP' and `stores`.`company`='MATALAN'

我很难理解这一点

我有以下代码:

$result=$db->query(" select `job_id`,`jobs`.`client` 
       from `stores` 
       left join `jobs` 
       on `jobs`.`client`=`stores`.`id` 
       where `stores`.`postcode`='BD5 8HP' 
         and `stores`.`company`='MATALAN' 
         and `jobs`.`description`='MONTHLY external - Clean Both sides of External Glazing, Frames, Ledges & Entrance Doors (up to 1.8m Height) - Including Black out windows - Removing cobwebs and dust from all areas' ")->fetch();
echo "info:";
print_r($result);
die();
查询完全不返回任何内容,aka$result是一个空数组

如果我通过PhpMyAdmin或从MySQL二进制客户机(在服务器上)运行完全相同的查询,我就得到了reults

PHP代码是一个prepare->execute构造,但由于得到的结果是空的,所以我尝试用直接查询替换它(仅用于测试目的)

我看了一个非常类似的主题,这表明问题与绑定有关,现在我在上面的查询中根本没有绑定,但结果是一个空字符串

运行其他查询,比如,
“select*fromtable”
会返回结果,所以我不知道这里会有什么错误

有什么想法/建议吗

作为脚注,我正在对远程服务器运行查询。会不会是因为这个角色

编辑:

虽然我收到了更改描述值的建议,但我不能这样做。该值是从PDF中读取的,并且一个位置可以有类似的值,所以使用LIKE和a%对我来说不太合适。我需要得到精确的匹配值

编辑2 好吧,问题似乎有点复杂,它的根本原因可能是更深层次的。如果我手动将字符串写入PHP代码,我会得到正确的结果,但是当我将其作为变量传递时,它似乎不再起作用。这是我剧本的一大块。脚本正在使用IMAP检查电子邮件如果电子邮件符合某些规则并且有附件,则会打开PDF格式的附件,将其转换为文本,提取一些图像并相应地更新数据库

$invoicedata=$a['attachment'];
                        $descriptorspec = array(
                           0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
                           1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
                           2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
                        );

                        $cwd = '/tmp';
                        $process = proc_open('pdftotext - -', $descriptorspec, $pipes, $cwd);

                        if (is_resource($process)) {

                            fwrite($pipes[0], $invoicedata);
                            fclose($pipes[0]);
                            $all_text=stream_get_contents($pipes[1]);
                            fclose($pipes[1]);

                            proc_close($process);
                            preg_match("/ARL SUPPORT SERVICES (.*)/",$all_text,$extracted);
                            $company=$extracted[1];
                            preg_match("/[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/",$all_text,$extracted);
                            $postcode=$extracted[0];
                            preg_match("/Date\n*(.*-)/",$all_text,$extracted);
                            $date=trim(str_replace("/","-",str_replace("-","",$extracted[1])));

                            $date=date("Y-m-d H:i:s",strtotime($date));

                            preg_match("/SPECIFICATION:((.|\n)*)EQUIPMENT/",$all_text,$extracted);
                            $job_desc=trim($extracted[1]));

                            preg_match("/Resource\n*(.*)/",$all_text,$extracted);
                            $who_signed=trim(str_replace("-","",$extracted[1]));


                            $db = new PDO('mysql:host=XXX.XXX.XXX.XXX;dbname=ZZZZZZ;charset=utf8', 'USER','PASSWORD');
                            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

                            $result=$db->query("select `job_id`,`jobs`.`client` from `stores` 
                            left join `jobs` on `jobs`.`client`=`stores`.`id`
                            where `stores`.`postcode`='$postcode' and `stores`.`company`='$company'
                            and `jobs`.`description`='$job_desc'")->fetch();
                        echo "info: ";
                        print_r($result);
                        die();
在这种情况下,
$result
为空

如果我这样做:

echo "select `job_id`,`jobs`.`client` from `stores` 
      left join `jobs` on `jobs`.`client`=`stores`.`id`
      where `stores`.`postcode`='$postcode' and `stores`.`company`='$company' and `jobs`.`description`='$job_desc'"
die();
它只会打印:

select `job_id`,`jobs`.`client` from `stores` left join `jobs` on `jobs`.`client`=`stores`.`id` where `stores`.`postcode`='BD5 8HP' and `stores`.`company`='MATALAN' and `jobs`.`description`='MONTHLY external - Clean Both sides of External Glazing, Frames, Ledges & Entrance Doors (up to 1.8m Height) - Including Black out windows - Removing cobwebs and dust from all areas'
如果我将其复制回我的PHP代码中,那么代码将正确执行,因此问题可能出在转换字符的某个地方。我认为这可能是由于endash/emdash,但使用
ord()
检查
$job\u desc
返回了字符45,这是正确的。而且&似乎是正确的


我的想法快用完了,是不是有什么明显的东西没有跳出来?

这个问题与从PDFTOTEXT输出中输入错误的ASCII字符有关

实现str_replace函数确实解决了这个问题


感谢所有的支持/建议。

是空数组还是空字符串?我会说它是一个名为false的布尔值;)你试过错误检查吗?对于PDO错误处理,请使用
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_异常):
。这将使它抛出异常,以便更容易看到问题。请在您的
WHERE
条件中尝试另一个
描述
:-)。或者只是
jobs.description,比如“每月外部%”
。我相信这会奏效的。问题是您的字符串传递到了查询。请仅尝试“从
存储中选择
作业id
作业
客户端
作业
客户端
=
存储
id
”上左连接
作业
,然后查看发生了什么…;-)我已经有:$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_异常);也不例外$结果是一个空字符串,如果我执行
->fetchAll()
,那么我有一个空数组,很抱歉造成混淆。跳过
作业
说明
部分会返回大量结果(比我需要的更多)。描述是一个很长的varchar,我讨厌它,但对此我无能为力,我确实需要对它进行过滤。如前所述,从命令行运行完全相同的查询将返回结果。。。。。