duanjie2940
2015-07-24 09:23
浏览 56
已采纳

如何在PDO MySQL中回显字符串?

I want php to echo string of text - a zone of the country from the database, but PDO does not want to spit out anything but arrays.

$sendToCountryCode = $_POST['sendToCountry'];

$sqlGetSendToCountryZone= "SELECT zone FROM table WHERE code = :country";
$stmtGetSendToCountryZone = $conn->prepare($sqlGetSendToCountryZone);
$stmtGetSendToCountryZone->bindParam(':country', $sendToCountryCode, PDO::PARAM_STR);
$stmtGetSendToCountryZone->execute(array(':country' => $sendToCountryCode));

$sendToCountryZone = $stmtGetSendToCountryZone->fetch();
var_dump($sendToCountryZone);
echo 'send to country code: ', $sendToCountryZone ,'<br>';

Google is not strong with me today

Notice: Array to string conversion in .... on line 10

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubi2014 2015-07-24 09:29
    已采纳

    Please use $sendToCountryZone = $stmtGetSendToCountryZone->fetch(PDO::FETCH_ASSOC); as it is recommended to use fetch () with the appropriate parameter since fetch () has several "fetching styles".

    Read more about it here

    Next please use $sendToCountryZone["zone"] as it will always return a string array.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题