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

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条)

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致