1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
<?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 TTypeAdrPService {
var $username = "zzImport";
var $password = "pwd";
var $server = "localhost";
var $port = "8889";
var $databasename = "MyDBsql";
var $tablename = "T_TypeAdr_P";
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);
}
/* Permet d'encoder les données en UTF8 et de faire passerelle entre MySQL et Flex*/
public function utf8_encode_array($array)
{
$retArray = Array ();
foreach($array as $keyA => $row)
{
foreach($row as $keyB => $value)
{
$retArray[$keyA][utf8_encode ($keyB)] = utf8_encode ($value);
}
}
return $retArray;
}
/**
* Returns all the rows from the table.
*
* Add authroization or any logical checks for secure access to your data
*
* @return array
*/
public function getAllT_TypeAdr_P() {
$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->Nom);
while (mysqli_stmt_fetch($stmt)) {
$rows[] = $row;
$Utf8Result = $this->utf8_encode_array($row);
mysqli_stmt_bind_result($stmt, $row->Nom);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $Utf8Result;
}
/**
* 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 getT_TypeAdr_PByID($itemID) {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where Nom=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
mysqli_stmt_bind_result($stmt, $row->Nom);
if(mysqli_stmt_fetch($stmt)) {
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 createT_TypeAdr_P($item) {
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (Nom) VALUES (?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 's', $item->Nom);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = $item->Nom;
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 updateT_TypeAdr_P($item) {
$stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET Nom=? WHERE Nom=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ss', $item->Nom, $item->Nom);
$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 deleteT_TypeAdr_P($itemID) {
$stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE Nom = ?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 's', $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 getT_TypeAdr_P_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->Nom);
while (mysqli_stmt_fetch($stmt)) {
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->Nom);
}
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);
}
}
}
?> |
Partager