5 Replies Latest reply on Nov 11, 2009 9:19 PM by EZ_paco99

    Unable to connect to the server to pull data from mysql

    EZ_paco99

      Hello,

       

      I am novice working with Flash Builder 4 and I just created a test application which runs well in my computer pulling data from Mysql using PHP and populating a datagrid. But when I transfered it to the my hosting provider failed. I have been doing some modifications to the gateway.php and amf.config.ini to solve some of the issues. Now the application try to run but doesn't populate the data in the datagrid. I included a tracking point in my data service file to read the connections variables, but they come up in blank. I highly appreciate any help. Here are my gateway.php, amf.config.ini and the data service.

       

      gateway.php

       

      <?php
      ini_set("display_errors", 1);
      $dir = dirname(__FILE__);
      $webroot = $_SERVER['DOCUMENT_ROOT'];
      $configfile = "$dir/amf_config.ini";

      $fp = fopen("tracking.txt", "a");

      //*********************************************************
      fwrite($fp, "1-config file " . $configfile . "\r\n");


      //default zend install directory
      $zenddir = $webroot. '/ZendFramework/library';
      //-$zenddir = $webroot;

      //*********************************************************
      fwrite($fp, "2-default zendir" . $zenddir . "\r\n");


      //Load ini file and locate zend directory
      if(file_exists($configfile)) {
           $arr=parse_ini_file($configfile,true);
           if(isset($arr['zend']['webroot'])){
                $webroot = $arr['zend']['webroot'];
                $zenddir = $webroot. '/ZendFramework/library';
           }
           if(isset($arr['zend']['zend_path'])){
                $zenddir = $arr['zend']['zend_path'];
           }
      }

      //*********************************************************
      fwrite($fp, "3-after zendir" . $zenddir . "\r\n");


      // Setup include path
      //add zend directory to include path
      set_include_path(get_include_path().PATH_SEPARATOR.$zenddir);

      // Initialize Zend Framework loader
      require_once 'Zend/Loader/Autoloader.php';
      //-require_once 'Autoloader.php';

      Zend_Loader_Autoloader::getInstance();
      // Load configuration
      $default_config = new Zend_Config(array("production" => false), true);
      $default_config->merge(new Zend_Config_Ini($configfile, 'zendamf'));
      $default_config->setReadOnly();
      $amf = $default_config->amf;

      //*********************************************************
      fwrite($fp, "4- configfile" . $dafault_config["production"] . "\r\n");

      // Store configuration in the registry
      Zend_Registry::set("amf-config", $amf);
      // Initialize AMF Server
      $server = new Zend_Amf_Server();
      $server->setProduction($amf->production);
      if(isset($amf->directories)) {
           $dirs = $amf->directories->toArray();
           foreach($dirs as $dir) {
               // get the first character of the path.
               // If it does not start with slash then it implies that the path is relative to webroot. Else it will be treated as absolute path
               $length = strlen($dir);
               $firstChar = $dir;
               if($length >= 1)
                    $firstChar = $dir[0];
              
               if($firstChar != "/"){
                    // if the directory is ./ path then we add the webroot only.
                    if($dir == "./"){                  
                         $server->addDirectory($webroot);
                    }else{
                         $tempPath = $webroot . "/" . $dir;
                          $server->addDirectory($tempPath);
                     }        
                }else{
                        $server->addDirectory($dir);             
                }
           }
      }

      //*********************************************************
      fwrite($fp, "5-temp path" . $tempPath . "=>" . "\r\n");
      fwrite($fp, "******************************************" . "\r\n");



      // Initialize introspector for non-production
      if(!$amf->production) {
           $server->setClass('Zend_Amf_Adobe_Introspector', '', array("config" => $default_config, "server" => $server));
              $server->setClass('Zend_Amf_Adobe_DbInspector', '', array("config" => $default_config, "server" => $server));
      }
      // Handle request
      echo $server->handle();
      ?>

      amf.config.ini
      [zend]
      ;set the absolute location path of webroot directory, example:
      ;Windows: C:\apache\www
      ;MAC/UNIX: /user/apache/www
      ;-webroot =c:/wamp/www/
      webroot = /home/frutiexp/public_html

      ;set the absolute location path of zend installation directory, example:
      ;Windows: C:\apache\PHPFrameworks\ZendFramework
      ;MAC/UNIX: /user/apache/PHPFrameworks/ZendFramework
      ;zend_path = /home/frutiexp/public_html/ZendFramework

      [zendamf]
      amf.production = true
      amf.directories[]=fb41/services
      ;amf.directories[]=./

      CoursesService.php


      <?php

      /**
      *  README for sample service
      *
      *  This generated sample service contains functions that illustrate typical service operations.
      *  Use these functions as a starting point for creating your own service implementation. Modify the
      *  function signatures, references to the database, and implementation according to your needs.
      *  Delete the functions that you do not use.
      *
      *  Save your changes and return to Flash Builder. In Flash Builder Data/Services View, refresh
      *  the service. Then drag service operations onto user interface components in Design View. For
      *  example, drag the getAllItems() operation onto a DataGrid.

      *  This code is for prototyping only.

      *  Authenticate the user prior to allowing them to call these methods. You can find more
      *  information at <link>
      *
      */
      class CoursesService {

           var $username = "myusername";
           var $password = "mypassword"
           var $server = "localhost";
           var $port = "3306";
           var $databasename = "frutiexp_trainsur";
           var $tablename = "courses";
           var $connection;

           /**
            * The constructor initializes the connection to database. Everytime a request is
            * received by Zend AMF, an instance of the service class is created and then the
            * requested method is invoked.
            */

           public function __construct() {
                  $this->connection = mysqli_connect(
                                                $this->server, 
                                                $this->username, 
                                                $this->password,
                                                $this->databasename,
                                                $this->port
                                           );
      $fp = fopen("./tracking.txt", "a");
      fwrite($fp, "1-service".  $databasename . " " . $username . "\r\n");
      fclose($fp);



                $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 getAllCourses() {




                $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->cou_id, $row->cou_title, $row->cou_overview, $row->cou_objectives);
               
               while (mysqli_stmt_fetch($stmt)) {
                 $rows[] = $row;
                 $row = new stdClass();
                 mysqli_stmt_bind_result($stmt, $row->cou_id, $row->cou_title, $row->cou_overview, $row->cou_objectives);
               }
               
                mysqli_stmt_free_result($stmt);
               mysqli_close($this->connection);
          
               return $rows;
           }

           /**
            * Returns the item corresponding to the value specified for the primary key.
            *
            * Add authroization or any logical checks for secure access to your data
            *
            *
            * @return stdClass