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
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();
As the stackoverflow's policy does not allow me to enclose too many links, please take ADDR for localhost
When you go which 8889 port number you try to hit MySQL directly which you are not supposed to be doing as well. Try using port 8888 and this command:
curl -F "rw_app_id=1" -F "code=test" -F "device_id=test2" ADDR:8888/promos/
or
curl -F "rw_app_id=1" -F "code=test" -F "device_id=test2" ADDR:8888/promocodes
(assuming you do have index.php inside promocodes folder)
3. Remember that when you try to hit the server with you web browser's navigation bar you do send a GET type request. If you need an alternative to curl, try using some web browser's plugin like "Poster" (dedicated for FireFox).
[��� 5.7.20-0ubuntu0.16.04.1����UW47HvY�ÿ÷�ÿ����������nfm@*g}
I am not sure what is fabric in MySQL. I've never seen this before, but this page seems to come from:
/etc/mysql/fabric.cfg
Modify the configuration file or remove any links to the main Apache configuration.
If you happen to have old_password=1
in your my.cnf
file you might try setting it to 0
and resetting your password.