dongwen5351
2012-03-30 01:27
浏览 244
已采纳

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

I'm trying to follow this tutorial http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app

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

index.php

<?php
    echo "Hello, PHP!";
?>

promocodes.php

<?php

class RedeemAPI {
    private $db;

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

    // Destructor - close DB connection
    function __destruct() {
        $this->db->close();
    }

    // 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->execute();
        $stmt->bind_result($id, $code, $unlock_code, $uses_remaining);
        while ($stmt->fetch()) {
            echo "$code has $uses_remaining uses remaining!";
        }
        $stmt->close();
    }
}

?>

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;
    $api->redeem();
    
    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题