Copy link to clipboard
Copied
Hi, I tried some basics with Flash Builder and PHP MySQL. I walked throught this tutorial http://www.flashrealtime.com/flash-builder-4-and-php-data-services/ but when I added a function btnSearch_clickHandler and launched the project in browser to test it, it gave me this error:
I don't know why is this happening. I followed the tutorial step by step. The only difference is that I use Windows 7 with WAMP and Tomas uses MacOS with MAMP
I uploaded my project http://www.mediafire.com/file/6ri44igt1hbssrf/phpConnect.zip , can someone take a look at it please? Thanks
Even if you are using Wamp it's the same, I want to remind you that you have to use port 3306 during the connection setup inside your Flex IDE.
Message was edited by Aldo Marsilio www.flashbackstage.com
Message was edited by: aldo marsilio
Copy link to clipboard
Copied
What does it tell when you use the Test operation to call the same operation in Flash Builder?
Thanks
Sunil
Copy link to clipboard
Copied
Test operation - Service: EmployeesService; Operation: getAllEmployees
InvocationTargetException: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() expects parameter 5 to be long, string given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 44
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 259
Warning: mysqli_prepare() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 60
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 259
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 64
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 259
Warning: mysqli_stmt_bind_result() expects parameter 1 to be mysqli_stmt, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 69
Warning: mysqli_stmt_fetch() expects parameter 1 to be mysqli_stmt, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 71
Warning: mysqli_stmt_free_result() expects parameter 1 to be mysqli_stmt, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 77
Warning: mysqli_close() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 78
/0/onResult˙˙˙˙ � Uflex.messaging.messages.AcknowledgeMessage correlationId clientId destination messageId timestamp timeToLive headers body IC8EF4525-730F-BAB2-DBAB-83FBBE072AC9 I65CC210E-A04D-CC48-4ADA-000037765A55 I06052A08-C992-9588-1B12-00005079FAB8 128561039300
And the PHP file is like this:
<?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 http://www.adobe.com/go/flex_security
*
*/
class EmployeesService {
var $username = "root";
var $password = "";
var $server = "localhost";
var $port = "";
var $databasename = "test";
var $tablename = "employees";
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
);
$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 getAllEmployees($q) {
$sql = "SELECT * FROM $this->tablename WHERE first_name LIKE '%$q%' OR last_name LIKE '%$q%' OR email_address LIKE '%$q%'";
$stmt = mysqli_prepare($this->connection,$sql);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date, $row->phone_no, $row->email_address, $row->job_title);
while (mysqli_stmt_fetch($stmt)) {
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date, $row->phone_no, $row->email_address, $row->job_title);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
/**
* Returns the item corresponding to the value specified for the primary key.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @return stdClass
*/
public function getEmployeesByID($itemID) {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where emp_no=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date, $row->phone_no, $row->email_address, $row->job_title);
if(mysqli_stmt_fetch($stmt)) {
$row->birth_date = new DateTime($row->birth_date);
$row->hire_date = new DateTime($row->hire_date);
return $row;
} else {
return null;
}
}
/**
* Returns the item corresponding to the value specified for the primary key.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @return stdClass
*/
public function createEmployees($item) {
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (birth_date, first_name, last_name, gender, hire_date, phone_no, email_address, job_title) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ssssssss', $item->birth_date->toString('YYYY-MM-dd HH:mm:ss'), $item->first_name, $item->last_name, $item->gender, $item->hire_date->toString('YYYY-MM-dd HH:mm:ss'), $item->phone_no, $item->email_address, $item->job_title);
$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;
}
/**
* Updates the passed item in the table.
*
* Add authorization or any logical checks for secure access to your data
*
* @param stdClass $item
* @return void
*/
public function updateEmployees($item) {
$stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET birth_date=?, first_name=?, last_name=?, gender=?, hire_date=?, phone_no=?, email_address=?, job_title=? WHERE emp_no=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ssssssssi', $item->birth_date->toString('YYYY-MM-dd HH:mm:ss'), $item->first_name, $item->last_name, $item->gender, $item->hire_date->toString('YYYY-MM-dd HH:mm:ss'), $item->phone_no, $item->email_address, $item->job_title, $item->emp_no);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
/**
* Deletes the item corresponding to the passed primary key value from
* the table.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @return void
*/
public function deleteEmployees($itemID) {
$stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE emp_no = ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
/**
* Returns the number of rows in the table.
*
* Add authorization or any logical checks for secure access to your data
*
*
*/
public function count() {
$stmt = mysqli_prepare($this->connection, "SELECT COUNT(*) AS COUNT FROM $this->tablename");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $rec_count);
$this->throwExceptionOnError();
mysqli_stmt_fetch($stmt);
$this->throwExceptionOnError();
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rec_count;
}
/**
* Returns $numItems rows starting from the $startIndex row from the
* table.
*
* Add authorization or any logical checks for secure access to your data
*
*
*
* @return array
*/
public function getEmployees_paged($startIndex, $numItems) {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename LIMIT ?, ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ii', $startIndex, $numItems);
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date, $row->phone_no, $row->email_address, $row->job_title);
while (mysqli_stmt_fetch($stmt)) {
$row->birth_date = new DateTime($row->birth_date);
$row->hire_date = new DateTime($row->hire_date);
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date, $row->phone_no, $row->email_address, $row->job_title);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
/**
* Utility 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);
}
}
}
?>
Copy link to clipboard
Copied
So, looks like there are errors when passing parameters, can you check your code are just hardcode the parameters for time being to check whether everything is working fine.
Thanks
-Sunil
Copy link to clipboard
Copied
Ok, I tried to not to change the generated PHP code and launch function getAllEmployeesResult.token = employeesService.getAllEmployees(); instead of getAllEmployeesResult.token = employeesService.getAllEmployees(txtSearch.text);
still the same error
Copy link to clipboard
Copied
What is the error when you try to run it from Test operation from the Data/Services panel?
Copy link to clipboard
Copied
InvocationTargetException: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() expects parameter 5 to be long, string given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 44
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 258
Warning: mysqli_prepare() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 58
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 258
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 61
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 258
Warning: mysqli_stmt_bind_result() expects parameter 1 to be mysqli_stmt, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 66
Warning: mysqli_stmt_fetch() expects parameter 1 to be mysqli_stmt, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 68
Warning: mysqli_stmt_free_result() expects parameter 1 to be mysqli_stmt, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 76
Warning: mysqli_close() expects parameter 1 to be mysqli, null given in C:\wamp\www\phpConnect\services\EmployeesService.php on line 77
/0/onResult˙˙˙˙ � Uflex.messaging.messages.AcknowledgeMessage correlationId clientId destination messageId timestamp timeToLive headers body I22F739C2-7008-D1FF-4C6F-C37EF031B6F4 I37DE091D-AC33-2488-4A61-00002154B7E3 I204A7F21-8C87-90C9-E2B3-0000211F7CC6 128622908400
Copy link to clipboard
Copied
i know this is an old post but in case someone stumbles onto it with the same problem, having just started with Flex, and using Xampp I had the same problem, but once I specified the port to mysql as 3306 - this problem stopped.
Hope it helps.
Copy link to clipboard
Copied
Even if you are using Wamp it's the same, I want to remind you that you have to use port 3306 during the connection setup inside your Flex IDE.
Message was edited by Aldo Marsilio www.flashbackstage.com
Message was edited by: aldo marsilio