fork download
  1. <?php
  2.  
  3. //if(isset($_POST["employee_id"])) {
  4. //$id=$_POST["employee_id"];
  5. $stmt = $con->prepare("SELECT name,address,gender,designation,age FROM tbl_employee WHERE id = 119");
  6.  
  7. /*Verificamos que la preparación fue correcta*/
  8. if ($stmt) {
  9. /*Si el campo id es VARCHAR cambias la "i" por una "s" en bind_param*/
  10. //$stmt->bind_param("i", $id);
  11. $stmt->execute();
  12. /*Aquí pasamos $stmt a nuestra función para que cree el arreglo asocitativo*/
  13. $arrResultado = get_result($stmt);
  14. }else{
  15. $arrResultado=array("error"=>$stmt->error);
  16. }
  17. echo json_encode($arrResultado);
  18. //}
  19.  
  20.  
  21. /*Esta es la función que menciono en el punto 2*/
  22. function get_result( $Statement ) {
  23. $RESULT = array();
  24. $Statement->store_result();
  25. for ( $i = 0; $i < $Statement->num_rows; $i++ ) {
  26. $Metadata = $Statement->result_metadata();
  27. $PARAMS = array();
  28. while ( $Field = $Metadata->fetch_field() ) {
  29. $PARAMS[] = &$RESULT[ $i ][ $Field->name ];
  30. }
  31. call_user_func_array( array( $Statement, 'bind_result' ), $PARAMS );
  32. $Statement->fetch();
  33. }
  34. return $RESULT;
  35. }
  36.  
  37.  
  38. var_dump($arrResultado);
Runtime error #stdin #stdout #stderr 0.02s 23416KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Notice:  Undefined variable: con in /home/EccV05/prog.php on line 5
PHP Fatal error:  Uncaught Error: Call to a member function prepare() on null in /home/EccV05/prog.php:5
Stack trace:
#0 {main}
  thrown in /home/EccV05/prog.php on line 5