php - 当从 mysql 在 php 中执行 strcmp 时,它返回 -6

标签 php mysql strcmp

我遇到了一个类似的问题,当我从 mysql 中提取一个值时,当我将它与文件名进行比较时,它总是返回 -6。仅当我从 mysql 提取信息时才会发生这种情况

path rp_suzrl250.jpg strFile rp_suzrl250.jpg  
strcmp value -6 



path 2009_Evo.jpg strFile 2009_Evo.jpg  
strcmp value -6  

path DSCF6495.JPG strFile DSCF6495.JPG  
strcmp value -6
    $strFile = $dbrow[bikepicture]; 
    if($dh = opendir($file)){
        while(($path = readdir($dh)) !== false){
            $path = (string)$path;
            $strFile = (string)$strFile;
            echo "filename:  " . $path . "  " . strcmp($path, $strFile) . "<br>";
            if ($path ===  $strFile){
                echo $path . " got here " . "<br />";
            }
        }
    }
    if (strtoupper($path) === strtoupper($strFile)){  }

转换为字符串失败并且转到上层失败。它返回-6。

最佳答案

我的“答案”仅包含问题,但它们可能会引导您找到解决方案。

你的 $strFile 是字符串吗?使用 var_dump($strFile) 你会得到什么? 我假设您的代码片段位于此类循环内:

$results = $cnn->query($query);
while ($dbrow = $results->fetch_array(MYSQLI_ASSOC)) {
    ...
}

如果这是正确的,您应该使用 $strFile = $dbrow['bikepicture'],因为否则 bikepicture 会被解释为常量。顺便问一下,您没有收到警告/错误吗?

关于php - 当从 mysql 在 php 中执行 strcmp 时,它返回 -6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19104463/

相关文章:

c - 使用两个指针的 Strcmp 导致段错误

php - 如何存储访问客户端的次数?

php - MySQL 查询非常慢

c - 在 if() 语句中使用 strcmp() 作为条件如何工作?

php - 动态数据库表属性(最佳实践)

html - 将 csv 中的嵌入代码存储在 mysql 中

c - strcmp 在用 fgets 读取的一行上

php - Laravel 5 日志中的最大文件

php - 如何使 key 对成为主要 key 对?

mysql - 多个group_concat