PHP Class for sending a response to Flash I've created this code to send a response to Flash which can be handled with AS2/AS3:

&lt;?php
    /**
     * Basic server-side API controls for Flash-PHP communication
     * @author Marty Wallace
     * @version 1.0.2
     */
    class API
    {
        // MySQL
        private $con;
        private $sql_hostname = '';
        private $sql_username = '';
        private $sql_password = '';
        private $sql_database = '';

        // Properties
        public $response;

        /**
         * Constructor
         */
        public function __construct()
        {
            // Attempt connection
            $this-&gt;con = mysql_connect(
                $this-&gt;sql_hostname,
                $this-&gt;sql_username,
                $this-&gt;sql_password
            );

            // Connection could not be established
            if(!$this-&gt;con)
            {
                $this-&gt;response = array(
                    "status" =&gt; "no_connection",
                    "message" =&gt; "Could not connect to MySQL, try again later."
                );

                $this-&gt;respond();
            }

            // Select database
            mysql_select_db($this-&gt;sql_database);
        }

        /**
         * Send response back to Flash
         */
        public function respond()
        {
            $ar = array();
            foreach($this-&gt;response as $key =&gt; $value)
                array_push($ar, $key . "=" . $value);

            die(implode("&amp;", $ar));
        }
    }
?&gt;


I'm not that great with PHP and the respond() function seems like it could be written a little better.. Any suggestions?
I have used PHP for a few years now, and here are my suggestions:

array_push() can be used to add multiple values into an array at once, but in your case, your pushing only one value in at a time which means you can use:

$ar[] = $key . "=" . $value

This should also speed up your code a little( What's better to use in PHP $array[] = $value or array_push($array, $value)?).

die() is normally used when there is an error. It spits out a message to the user. If you are using this code to just connect to a MySQL database then change die(implode("&amp;", $ar)); to  echo(implode("&amp;", $ar));

But honestly, you should be able to take out the respond() function if you are only using it to send an array to flash.

        // Connection could not be established
        if(!$this-&gt;con)
        {
            $this-&gt;response = array(
                "status" =&gt; "no_connection",
                "message" =&gt; "Could not connect to MySQL, try again later."
            );

             echo(implode("&amp;", $this-&gt;response));
        }