Mysqli查询没有结果

时间:2017-03-04 23:32:59

标签: php mysql mysqli prepared-statement

我在mysqli准备查询中遇到问题,我无法弄清楚出了什么问题。

在phpmyadmin中,我正在编写此查询

<body onload="load();">
   <input class="zipCode inputfield" />
</body>

我得到了一个成功的结果。

enter image description here

当我尝试用mysqli prepare语句执行此操作时,我收到错误。

SELECT `country_id` FROM `oa_country` WHERE `name` = "Ελλάδα"

打印$ result打印这些数据。

function getCountryId($country) {
    print($country); \\prints "Ελλάδα" or anything else, even countries in latin letters.
    $db = mysqli_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
    $result = mysqli_prepare($db, "SELECT `country_id` FROM `oa_country` WHERE `name` = ? ;");
    mysqli_stmt_bind_param($result, 's', $country);
    mysqli_stmt_execute($result);
    mysqli_stmt_bind_result($result, $countcountry);
    print_r($result);\\ see below.
    while(mysqli_stmt_fetch($result))
      {
            $countryid = $countcountry;

      }
    mysqli_stmt_close($result);
    mysqli_close($db);

    echo $countryid; \\undefined variable countryid
    return $countryid;
}

奇怪的是,它过去常常起作用,但突然停止了,我无法解释原因!

P.S。所有插入都使用mysqli + prepare语句。 像这样的查询停止了工作。

更新1。

我在班级上面记录了这个错误

mysqli_stmt Object
(
    [affected_rows] => -1
    [insert_id] => 0
    [num_rows] => 0
    [param_count] => 1
    [field_count] => 1
    [errno] => 0
    [error] => 
    [error_list] => Array
        (
        )

    [sqlstate] => 00000
    [id] => 1
)

现在我收到了这个错误。

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Column 'country_id' cannot be null' in /some/url/lib/registerClass.php:49 Stack trace: #0 /some/url/lib/registerClass.php(49): mysqli_stmt_execute(Object(mysqli_stmt)) #1 /some/url/register.php(34): RegisterLibrary->Address(21267, 'kapa\n', '\xCE\x9D\xCE\xAC\xCF\x84\xCF\x83\xCE\xB9\xCE\xBF\xCF\x82', 'oriste', 'pws', '123123', 'asdasd', '4121sadsa', 'sadas', '13322', '\xCE\x95\xCE\xBB\xCE\xBB\xCE\xAC\xCE\xB4\xCE\xB1', '\xCE\x91\xCF\x84\xCF\x84\xCE\xB9\xCE\xBA\xCE\xAE') 变量之下,我将字符集设置为utf8。

$db

1 个答案:

答案 0 :(得分:1)

它看起来像charset问题

尝试设置mysqli_set_charset