2012-03-30 01:27
浏览 244

PHP / MySQL新手得到的数据包乱序

I'm trying to follow this tutorial

I'm about half way down the page Verifying PHP/MySQL functionality and am stuck.

I just set up MAMP for the first time. I have two files in my MAMP htdocs directory


    echo "Hello, PHP!";



class RedeemAPI {
    private $db;

    // Constructor - open DB connection
    function __construct() {
        $this->db = new mysqli('localhost', 'root', 'root', 'promos');

    // Destructor - close DB connection
    function __destruct() {

    // Main method to redeem a code
    function redeem() {
        // Print all codes in database
        echo "Hello, PHP!";
        $stmt = $this->db->prepare('SELECT id, code, unlock_code, uses_remaining FROM rw_promo_code');
        echo "Hello, PHP!";
        $stmt->bind_result($id, $code, $unlock_code, $uses_remaining);
        while ($stmt->fetch()) {
            echo "$code has $uses_remaining uses remaining!";


when I go to http://localhost:8888/index.php I get

"Hello, PHP!";

when I go to http://localhost:8889/index.php I get the following gibberish

H��� 5.5.9�G���}Se"tHIr�ÿ÷�€����������(ja&7"BfZoB<�mysql_native_password!��ÿ„#08S01Got packets out of order

when I go to http://localhost:8888/promocodes.php I get


when I go to http://localhost:8889/promocodes.php I get the following gibberish

H��� 5.5.9�H���x%J'"s@#�ÿ÷�€����������-YX0#_89T|50�mysql_native_password!��ÿ„#08S01Got packets out of order

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

  • dse55384 2012-03-30 20:49

    Found the problem, when I copied in the new RedeemAPI class I deleted the code that actually uses the class.

    // This is the first thing that gets called when this page is loaded
    // Creates a new instance of the RedeemAPI class and calls the redeem method
    $api = new RedeemAPI;
    解决 无用
    打赏 举报

相关推荐 更多相似问题