| @@ 227-323 (lines=97) @@ | ||
| 224 | * @param int|NULL $arrayIndexEndValue |
|
| 225 | * @return array |
|
| 226 | */ |
|
| 227 | function _fetch($result, $arrayIndexEndValue = NULL) |
|
| 228 | { |
|
| 229 | if($this->use_prepared_statements != 'Y') |
|
| 230 | { |
|
| 231 | return parent::_fetch($result, $arrayIndexEndValue); |
|
| 232 | } |
|
| 233 | $output = array(); |
|
| 234 | if(!$this->isConnected() || $this->isError() || !$result) |
|
| 235 | { |
|
| 236 | return $output; |
|
| 237 | } |
|
| 238 | ||
| 239 | // Prepared stements: bind result variable and fetch data |
|
| 240 | $stmt = $result; |
|
| 241 | $meta = mysqli_stmt_result_metadata($stmt); |
|
| 242 | $fields = mysqli_fetch_fields($meta); |
|
| 243 | ||
| 244 | /** |
|
| 245 | * Mysqli has a bug that causes LONGTEXT columns not to get loaded |
|
| 246 | * Unless store_result is called before |
|
| 247 | * MYSQLI_TYPE for longtext is 252 |
|
| 248 | */ |
|
| 249 | $longtext_exists = false; |
|
| 250 | foreach($fields as $field) |
|
| 251 | { |
|
| 252 | if(isset($resultArray[$field->name])) // When joined tables are used and the same column name appears twice, we should add it separately, otherwise bind_result fails |
|
| 253 | { |
|
| 254 | $field->name = 'repeat_' . $field->name; |
|
| 255 | } |
|
| 256 | ||
| 257 | // Array passed needs to contain references, not values |
|
| 258 | $row[$field->name] = ""; |
|
| 259 | $resultArray[$field->name] = &$row[$field->name]; |
|
| 260 | ||
| 261 | if($field->type == 252) |
|
| 262 | { |
|
| 263 | $longtext_exists = true; |
|
| 264 | } |
|
| 265 | } |
|
| 266 | $resultArray = array_merge(array($stmt), $resultArray); |
|
| 267 | ||
| 268 | if($longtext_exists) |
|
| 269 | { |
|
| 270 | mysqli_stmt_store_result($stmt); |
|
| 271 | } |
|
| 272 | ||
| 273 | call_user_func_array('mysqli_stmt_bind_result', $resultArray); |
|
| 274 | ||
| 275 | $rows = array(); |
|
| 276 | while(mysqli_stmt_fetch($stmt)) |
|
| 277 | { |
|
| 278 | $resultObject = new stdClass(); |
|
| 279 | ||
| 280 | foreach($resultArray as $key => $value) |
|
| 281 | { |
|
| 282 | if($key === 0) |
|
| 283 | { |
|
| 284 | continue; // Skip stmt object |
|
| 285 | } |
|
| 286 | if(strpos($key, 'repeat_')) |
|
| 287 | { |
|
| 288 | $key = substr($key, 6); |
|
| 289 | } |
|
| 290 | $resultObject->$key = $value; |
|
| 291 | } |
|
| 292 | ||
| 293 | $rows[] = $resultObject; |
|
| 294 | } |
|
| 295 | ||
| 296 | mysqli_stmt_close($stmt); |
|
| 297 | ||
| 298 | if($arrayIndexEndValue) |
|
| 299 | { |
|
| 300 | foreach($rows as $row) |
|
| 301 | { |
|
| 302 | $output[$arrayIndexEndValue--] = $row; |
|
| 303 | } |
|
| 304 | } |
|
| 305 | else |
|
| 306 | { |
|
| 307 | $output = $rows; |
|
| 308 | } |
|
| 309 | ||
| 310 | if(count($output) == 1) |
|
| 311 | { |
|
| 312 | if(isset($arrayIndexEndValue)) |
|
| 313 | { |
|
| 314 | return $output; |
|
| 315 | } |
|
| 316 | else |
|
| 317 | { |
|
| 318 | return $output[0]; |
|
| 319 | } |
|
| 320 | } |
|
| 321 | ||
| 322 | return $output; |
|
| 323 | } |
|
| 324 | ||
| 325 | /** |
|
| 326 | * Handles insertAct |
|
| @@ 285-381 (lines=97) @@ | ||
| 282 | * @param int|NULL $arrayIndexEndValue |
|
| 283 | * @return array |
|
| 284 | */ |
|
| 285 | function _fetch($result, $arrayIndexEndValue = NULL) |
|
| 286 | { |
|
| 287 | if($this->use_prepared_statements != 'Y') |
|
| 288 | { |
|
| 289 | return parent::_fetch($result, $arrayIndexEndValue); |
|
| 290 | } |
|
| 291 | $output = array(); |
|
| 292 | if(!$this->isConnected() || $this->isError() || !$result) |
|
| 293 | { |
|
| 294 | return $output; |
|
| 295 | } |
|
| 296 | ||
| 297 | // Prepared stements: bind result variable and fetch data |
|
| 298 | $stmt = $result; |
|
| 299 | $meta = mysqli_stmt_result_metadata($stmt); |
|
| 300 | $fields = mysqli_fetch_fields($meta); |
|
| 301 | ||
| 302 | /** |
|
| 303 | * Mysqli has a bug that causes LONGTEXT columns not to get loaded |
|
| 304 | * Unless store_result is called before |
|
| 305 | * MYSQLI_TYPE for longtext is 252 |
|
| 306 | */ |
|
| 307 | $longtext_exists = false; |
|
| 308 | foreach($fields as $field) |
|
| 309 | { |
|
| 310 | if(isset($resultArray[$field->name])) // When joined tables are used and the same column name appears twice, we should add it separately, otherwise bind_result fails |
|
| 311 | { |
|
| 312 | $field->name = 'repeat_' . $field->name; |
|
| 313 | } |
|
| 314 | ||
| 315 | // Array passed needs to contain references, not values |
|
| 316 | $row[$field->name] = ""; |
|
| 317 | $resultArray[$field->name] = &$row[$field->name]; |
|
| 318 | ||
| 319 | if($field->type == 252) |
|
| 320 | { |
|
| 321 | $longtext_exists = true; |
|
| 322 | } |
|
| 323 | } |
|
| 324 | $resultArray = array_merge(array($stmt), $resultArray); |
|
| 325 | ||
| 326 | if($longtext_exists) |
|
| 327 | { |
|
| 328 | mysqli_stmt_store_result($stmt); |
|
| 329 | } |
|
| 330 | ||
| 331 | call_user_func_array('mysqli_stmt_bind_result', $resultArray); |
|
| 332 | ||
| 333 | $rows = array(); |
|
| 334 | while(mysqli_stmt_fetch($stmt)) |
|
| 335 | { |
|
| 336 | $resultObject = new stdClass(); |
|
| 337 | ||
| 338 | foreach($resultArray as $key => $value) |
|
| 339 | { |
|
| 340 | if($key === 0) |
|
| 341 | { |
|
| 342 | continue; // Skip stmt object |
|
| 343 | } |
|
| 344 | if(strpos($key, 'repeat_')) |
|
| 345 | { |
|
| 346 | $key = substr($key, 6); |
|
| 347 | } |
|
| 348 | $resultObject->$key = $value; |
|
| 349 | } |
|
| 350 | ||
| 351 | $rows[] = $resultObject; |
|
| 352 | } |
|
| 353 | ||
| 354 | mysqli_stmt_close($stmt); |
|
| 355 | ||
| 356 | if($arrayIndexEndValue) |
|
| 357 | { |
|
| 358 | foreach($rows as $row) |
|
| 359 | { |
|
| 360 | $output[$arrayIndexEndValue--] = $row; |
|
| 361 | } |
|
| 362 | } |
|
| 363 | else |
|
| 364 | { |
|
| 365 | $output = $rows; |
|
| 366 | } |
|
| 367 | ||
| 368 | if(count($output) == 1) |
|
| 369 | { |
|
| 370 | if(isset($arrayIndexEndValue)) |
|
| 371 | { |
|
| 372 | return $output; |
|
| 373 | } |
|
| 374 | else |
|
| 375 | { |
|
| 376 | return $output[0]; |
|
| 377 | } |
|
| 378 | } |
|
| 379 | ||
| 380 | return $output; |
|
| 381 | } |
|
| 382 | ||
| 383 | /** |
|
| 384 | * Handles insertAct |
|