字符串不同但在php中等于

时间:2015-09-24 14:29:33

标签: php vtiger

我正在使用eclipse编辑器。我在vtiger 5.4中编程。在我的文件config.inc.php中,变量$ default_charset被设置为

$default_charset = 'UTF-8';

我正在尝试使用下一个变量

在mysql中进行sql查询
$sql = "select cod_dpto from vtiger_ubi where dpto='" . $dpto . "'";

当我打印变量$dpto时,我得到"SAÑA",但执行查询mysql

$adb->query ( $sql );

不起作用。但是当我将我的查询修改为:

$sql = "select cod_dpto from vtiger_ubi where dpto='SAÑA'";

指令

$adb->query ( $sql );

返回我需要的值。

你能帮帮我吗,我怎样才能转换我的变量$dpto,以便sql查询运行良好。

修改

我尝试使用下面的代码进行查询,没有vtiger,并且我得到0个结果,因为两个变量和写'SAÑA'的情况

$servername = "localhost";
$username = "root";
$password = "peru2006";
$dbname = "consuladoperurio_com_br_2";
$port = "3306";

// Create connection
$conn = new mysqli ( $servername, $username, $password, $dbname, $port );
// Check connection
if ($conn->connect_error) {
die ( "Connection failed: " . $conn->connect_error );
}
$sql = "select cod_dpto from vtiger_ubigeo where dpto='$dpto'";
echo $sql;
$result = $conn->query ( $sql );
if ($result->num_rows > 0) {
// output data of each row
while ( $row = $result->fetch_assoc () ) {
    echo "id: " . $row ["cod_dpto"] "<br>";
}
} else {
echo "0 results";
}
$conn->close ();

1 个答案:

答案 0 :(得分:-1)

您的Select语句如下所示:

$sql = "select cod_dpto from vtiger_ubi where dpto='".SAÑA."';

你可能希望它看起来像:

$sql = "select cod_dpto from vtiger_ubi where dpto='$dpto'";

注意没有concat运算符,变量只包含在单引号中。