4 Replies Latest reply on May 10, 2010 2:47 PM by nikos101

    Code generated in FB 4 for php zend service

    nikos101 Level 2

      I am trying the data generation stuff for php in FB 4

       

      I used to use amfphp and my class would look like this

       


      <?php
      error_reporting(E_ALL);

       

      require('DB_CONSTANTS.php');

       


      class AudioService{

       

          var $connection;

       

          function AudioService(){

       

              $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
              mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

          }

       

       

       


         

       


          function checkResetPasswordKey($key){

       


              if (!eregi("^[0-9a-zA-Z]{50}$",$
      key)) {
                  throw new Exception('Bad key');
              }

       

       

       


              /* Verify that user is in database */
              $q = "SELECT * FROM tbusers WHERE forgotPassKey = '$key' AND
      now() < forgotPassExpiry";
              $result = mysql_query($q, $this->connection);

              if (!$result) {
                  $message  = 'Invalid query: ' . mysql_error() . "\n";
                  $message .= 'Whole query: ' . $query;
                  throw new Exception($message);
               }

       

              if ((mysql_numrows($result) < 1)) {
                  //throw new Exception('Your ');
              }
              return $result ;

       

          }
      }

      ?>

       


      however in the code generated like FB 4 it looks like this, I wanted to know what advantages this has over my method.
      Thanks

       

      <?php

       

      class service {

       

          /*var $username = "nik";
          var $password = "tat0W";*/
          var $username = "root";
          var $password = "";
         
          
         
          var $server = "localhost";
         
         
          var $port = "";
          var $databasename = "nikk";
          var $tablename = "contactlist";

       

          var $connection;

       

          public function __construct() {
                $this->connection = mysqli_connect(
                                        $this->server, 
                                        $this->username, 
                                        $this->password,
                                         $this->databasename
                                    );

       

              $this->throwExceptionOnError($this->connection);
          }


          /**
           * Returns all the rows from the table.
           *
           * Add authroization or any logical checks for secure access to your data
           *
           * @return array
           */
          public function getAllTbrawcontactlist() {

       

              $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");       
              $this->throwExceptionOnError();
             
              mysqli_stmt_execute($stmt);
              $this->throwExceptionOnError();
             
              $rows = array();
             
              mysqli_stmt_bind_result($stmt, $row->id, $row->email, $row->dateCreated, $row->wantsEmails);
             
              while (mysqli_stmt_fetch($stmt)) {
                $rows[] = $row;
                $row = new stdClass();
                mysqli_stmt_bind_result($stmt, $row->id, $row->email, $row->dateCreated, $row->wantsEmails);
              }
             
              mysqli_stmt_free_result($stmt);
              mysqli_close($this->connection);
         
              return $rows;
          }

       

       


          private function throwExceptionOnError($link = null) {
               if($link == null) {
                  $link = $this->connection;
              }
              if(mysqli_error($link)) {
                  $msg = mysqli_errno($link) . ": " . mysqli_error($link);
                  throw new Exception('MySQL Error - '. $msg);
               }       
          }
      }

       

      ?>