3 Replies Latest reply on Aug 5, 2010 8:06 AM by memBrainStudios

    Problem connecting to PHP data services in FB4

    memBrainStudios

      Hi there,

       

      I'm relatively new to web development.  I have successfully setup Apache  HTTP server and set up my web root in "C:\Web\root".  I also installed PHP, MySQL Server, and PHPMyAdmin on my computer.  Everything has been  tested and everything works correctly (as far as I can tell).

       

      I am trying to run the "Build an App in an Hour" tutorial.  I successfully completed the first video.  Everything worked correctly and displayed properly in the browser window when I ran the project.  Following the second video, I click on connect to Data/Services, and then select PHP services.  This takes me to the Configure PHP Service form.  I browse to "EmployeeService.php" located in "C:\Web\root\TestDrive\services", but I get a message "The selected PHP file should be under the web root of the current project's server.", and I cannot proceed any further.  I have tried this on both Flash Builder 4 Plug-in for Eclipse and the stand alone version of FB4 to the same result.  I am working on a time sensitive project and need to figure out how to resolve this problem ASAP.  What is this problem, and how do I fix it?

        • 1. Re: Problem connecting to PHP data services in FB4
          memBrainStudios Level 1

          Ok, I figured out what was causing the hangup.  I had to change the localhost settings from localhost:80 to localhost.  I can now access the PHP services offered in the file.  However, I now have a new problem.  When I go to configure the return type of my selected function, I get an error:

          There was an error while invoking the operation. Check your operation inputs or server code and try invoking the operation again.

          Reason:
          Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'test'@'localhost' (using password: YES) in C:\Web\root\TestDrive\services\EmployeeService.php on line 25

          Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\Web\root\TestDrive\services\EmployeeService.php on line 289

          Warning: mysqli_prepare() expects parameter 1 to be mysqli, boolean given in C:\Web\root\TestDrive\services\EmployeeService.php on line 47

          Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\Web\root\TestDrive\services\EmployeeService.php on line 289

          Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, null given in C:\Web\root\TestDrive\services\EmployeeService.php on line 51

          Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\Web\root\TestDrive\services\EmployeeService.php on line 289

          Warning: mysqli_stmt_bind_result() expects parameter 1 to be mysqli_stmt, null given in C:\Web\root\TestDrive\services\EmployeeService.php on line 59

          Warning: mysqli_stmt_fetch() expects parameter 1 to be mysqli_stmt, null given in C:\Web\root\TestDrive\services\EmployeeService.php on line 61

          Warning: mysqli_stmt_free_result() expects parameter 1 to be mysqli_stmt, null given in C:\Web\root\TestDrive\services\EmployeeService.php on line 71

          Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in C:\Web\root\TestDrive\services\EmployeeService.php on line 72
             /0/onResultÿÿÿÿ � Uflex.messaging.messages.AcknowledgeMessage correlationId clientId destination messageId timestamp timeToLive headers body I1216BD4C-6B09-B9AC-4882-150B8DBA468B I510191A1-A1C8-CD69-8B53-00002E0D4767  I5BB8EE9F-DAE4-C809-92D3-00003B5EB058  128083544900      

          Here is the code:

          <?php 
          /** 
           * This sample service contains functions that illustrate typical
           * service operations. This code is for prototyping only. 
           *  
           *  Authenticate users before allowing them to call these methods. 
           */ 
          
          class EmployeeService { 
            var $username = "test"; 
            var $password = "test"; 
            var $server = "localhost"; 
            var $port = "3306"; 
            var $databasename = "testdrive_db"; 
            var $tablename = "employees"; 
            
            var $connection; 
            public function __construct() { 
              $this->connection = mysqli_connect( 
                                 $this->server,  
                                 $this->username,  
                                 $this->password, 
                                 $this->databasename, 
                                 $this->port 
                                 ); 
              
              $this->throwExceptionOnError($this->connection); 
            } 
          
            public function getEmployees() {
               $stmt = mysqli_prepare($this->connection,
                    "SELECT
                        employees.id,
                        employees.firstname,
                        employees.lastname,
                        employees.title,
                        employees.departmentid,
                        employees.officephone,
                        employees.cellphone,
                        employees.email,
                        employees.street,
                        employees.city,
                        employees.state,
                        employees.zipcode,
                        employees.office,
                        employees.photofile
                     FROM employees");     
                   
                $this->throwExceptionOnError();
          
                mysqli_stmt_execute($stmt);
                $this->throwExceptionOnError();
          
                $rows = array();
                mysqli_stmt_bind_result($stmt, $row->id, $row->firstname,
                              $row->lastname, $row->title, $row->departmentid,
                              $row->officephone, $row->cellphone, $row->email,  
                              $row->street, $row->city, $row->state, 
                              $row->zipcode, $row->office, $row->photofile);
          
                while (mysqli_stmt_fetch($stmt)) {
                    $rows[] = $row;
                    $row = new stdClass();
                    mysqli_stmt_bind_result($stmt,  $row->id, $row->firstname,
                              $row->lastname, $row->title, $row->departmentid,
                              $row->officephone, $row->cellphone, $row->email,  
                              $row->street, $row->city, $row->state, 
                              $row->zipcode, $row->office, $row->photofile);
                }
          
                mysqli_stmt_free_result($stmt);
                mysqli_close($this->connection);
          
                return $rows;
            }  
          
            public function getDepartments() {
               $stmt = mysqli_prepare($this->connection,
                    "SELECT
                        departments.id,
                        departments.name,
                        departments.manager,
                        departments.costcenter,
                        departments.businessunit,
                     departments.budget,
                     departments.actualexpenses,
                     departments.estsalary,
                        departments.actualsalary,
                        departments.esttravel,
                        departments.actualtravel,
                     departments.estsupplies,
                        departments.actualsupplies,
                        departments.estcontractors,
                        departments.actualcontractors
                     FROM departments");
                $this->throwExceptionOnError();
          
                mysqli_stmt_execute($stmt);
                $this->throwExceptionOnError();
          
                $rows = array();
                mysqli_stmt_bind_result($stmt, $row->id, $row->name,
                              $row->manager, $row->costcenter, $row->businessunit,
                        $row->budget, $row->actualexpenses,$row->estsalary, $row->actualsalary,
                        $row->esttravel, $row->actualtravel,$row->estsupplies, $row->actualsupplies,
                              $row->estcontractors, $row->actualcontractors);
          
                while (mysqli_stmt_fetch($stmt)) {
                    $rows[] = $row;
                    $row = new stdClass();
                    mysqli_stmt_bind_result($stmt, $row->id, $row->name,
                                   $row->manager, $row->costcenter, $row->businessunit,
                                   $row->budget, $row->actualexpenses,$row->estsalary, $row->actualsalary,
                        $row->esttravel, $row->actualtravel,$row->estsupplies, $row->actualsupplies,
                              $row->estcontractors, $row->actualcontractors);
                }
          
                mysqli_stmt_free_result($stmt);
                mysqli_close($this->connection);
          
                return $rows;
            }  
          
          
            public function getEmployeesByID($itemID) {
               $stmt = mysqli_prepare($this->connection,
                    "SELECT
                        employees.title,
                        employees.street,
                        employees.id,
                        employees.firstname,
                        employees.lastname,
                        employees.cellphone,
                        employees.departmentid,
                        employees.zipcode,
                        employees.office,
                        employees.email,
                        employees.state,
                        employees.officephone,
                        employees.photofile,
                        employees.city
                     FROM employees where employees.id=?");
                $this->throwExceptionOnError();
                    
                mysqli_stmt_bind_param($stmt, 'i', $itemID);
                $this->throwExceptionOnError();
          
                mysqli_stmt_execute($stmt);
                $this->throwExceptionOnError();
          
                $rows = array();
                mysqli_stmt_bind_result($stmt, $row->title, $row->street, $row->id, 
                                        $row->firstname, $row->lastname, $row->cellphone,
                                        $row->departmentid, $row->zipcode, $row->office, 
                                        $row->email, $row->state, $row->officephone ,
                                        $row->photofile, $row->city);
          
                if (mysqli_stmt_fetch($stmt)) {
                            return $row;
                } else {
                            return null;
                    }
          
                mysqli_stmt_free_result($stmt);
                mysqli_close($this->connection);
          
            }  
          
            public function getEmployeesByName($searchStr) {
               $stmt = mysqli_prepare($this->connection,
                    "SELECT
                        employees.title,
                        employees.street,
                        employees.id,
                        employees.firstname,
                        employees.lastname,
                        employees.cellphone,
                        employees.departmentid,
                        employees.zipcode,
                        employees.office,
                        employees.email,
                        employees.state,
                        employees.officephone,
                        employees.photofile,
                        employees.city
                     FROM employees where employees.lastName LIKE ?");
                $this->throwExceptionOnError();
                    
                mysqli_stmt_bind_param($stmt, 's', $searchStr);
                $this->throwExceptionOnError();
          
                mysqli_stmt_execute($stmt);
                $this->throwExceptionOnError();
          
                $rows = array();
                mysqli_stmt_bind_result($stmt, $row->title, $row->street, $row->id, 
                                        $row->firstname, $row->lastname, $row->cellphone,
                                        $row->departmentid, $row->zipcode, $row->office, 
                                        $row->email, $row->state, $row->officephone ,
                                        $row->photofile, $row->city);
          
                while (mysqli_stmt_fetch($stmt)) {
                    $rows[] = $row;
                    $row = new stdClass();
                    mysqli_stmt_bind_result($stmt, $row->title, $row->street, $row->id, 
                                        $row->firstname, $row->lastname, $row->cellphone,
                                        $row->departmentid, $row->zipcode, $row->office, 
                                        $row->email, $row->state, $row->officephone ,
                                        $row->photofile, $row->city);
                }
          
                mysqli_stmt_free_result($stmt);
                mysqli_close($this->connection);
          
                return $rows;
          
            }  
          
             public function createEmployee($item) {
               $stmt = mysqli_prepare($this->connection,
                    "INSERT INTO employees (
                         firstname,lastname,title,departmentid,officephone,cellphone,      
                         email,street,city,state,zipcode,office,photofile) 
                    VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?)");
               $this->throwExceptionOnError();
               
               mysqli_bind_param($stmt, 'sssisssssssss', $item->firstname, $item->lastname,
                    $item->title, $item->departmentid, $item->officephone, $item->cellphone,
                    $item->email, $item->street, $item->city, $item->state,
                    $item->zipcode, $item->office, $item->photofile
               );
               $this->throwExceptionOnError();
          
               mysqli_stmt_execute($stmt);
               $this->throwExceptionOnError();
               
               $autoid = mysqli_stmt_insert_id($stmt);
               
               mysqli_stmt_free_result($stmt);
               mysqli_close($this->connection);
               
               return $autoid;
            }
          
            public function deleteEmployee($itemID) {
               $stmt = mysqli_prepare($this->connection,
                    "DELETE FROM employees WHERE id = ?");
               $this->throwExceptionOnError();
               
               mysqli_bind_param($stmt, 'i', $itemID);
          
               mysqli_stmt_execute($stmt);
               $this->throwExceptionOnError();
          
               mysqli_stmt_free_result($stmt);
               mysqli_close($this->connection);
            }
          
            public function updateEmployee($item) {
               $stmt = mysqli_prepare($this->connection,
                    "UPDATE employees SET
                         firstname=?,lastname=?,title=?,departmentid=?,officephone=?,cellphone=?,      
                         email=?,street=?,city=?,state=?,zipcode=?,office=?,photofile=?
                         WHERE id=?");
               $this->throwExceptionOnError();
          
               mysqli_bind_param($stmt, 'sssisssssssssi', $item->firstname, $item->lastname,
                    $item->title, $item->departmentid, $item->officephone, $item->cellphone,
                    $item->email, $item->street, $item->city, $item->state,
                    $item->zipcode, $item->office, $item->photofile,$item->id
               );
               $this->throwExceptionOnError();
          
               mysqli_stmt_execute($stmt);
               $this->throwExceptionOnError();
          
               mysqli_stmt_free_result($stmt);
               mysqli_close($this->connection);
            }
          
          /** 
            * Utitity function to throw an exception if an error occurs 
            * while running a mysql command. 
            */ 
            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); 
              }         
            } 
           
          } 
          ?>
          
          

          I used the included sql files to create the DB through PHPMyAdmin.  I also created a new user called test with a password test, and gave it access to the database to match the inputs to the code.  So now what do I do?

          • 2. Re: Problem connecting to PHP data services in FB4
            SunilAdobe Adobe Employee

            Can you resolve your test user's permissions to access the tables and try again.

             

            -Sunil

            • 3. Re: Problem connecting to PHP data services in FB4
              memBrainStudios Level 1

              I managed to get everything running, but I'm not sure why.  I ended up having to give the test account the same priviledges are the root account, but that doesn't tell me why I can't seem to get it to work specifically with just this one DB on its own...