Advertisement
Guest User

Untitled

a guest
May 26th, 2019
1,407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <?php
  2. @header('Content-type: application/json');
  3.  
  4. header('Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept"');
  5. header("Access-Control-Allow-Origin: *", false);
  6.  
  7.    // Define database connection parameters
  8.    $hn      = 'localhost';
  9.    $un      = 'root';
  10.    $pwd     = '';
  11.    $db      = 'karina';
  12.    $cs      = 'utf8';
  13.  
  14.       $cpf=$_GET["cpf"];
  15.  
  16.    // Set up the PDO parameters
  17.    $dsn     = "mysql:host=" . $hn . ";port=3306;dbname=" . $db . ";charset=" . $cs;
  18.    $opt     = array(
  19.                         PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
  20.                         PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
  21.                         PDO::ATTR_EMULATE_PREPARES   => false,
  22.                        );
  23.    // Create a PDO instance (connect to the database)
  24.    $pdo     = new PDO($dsn, $un, $pwd, $opt);
  25.    $data    = array();
  26.  
  27.    // Attempt to query database table and retrieve data
  28.    try {
  29.       $stmt     = $pdo->query("SELECT id_paciente, nome, cpf, idade, peso, altura, cartao_sus, endereco, telefone FROM paciente WHERE cpf = '$cpf'");
  30.       while($row  = $stmt->fetch(PDO::FETCH_OBJ))
  31.       {
  32.          // Assign each row of data to associative array
  33.          $data[] = $row;
  34.       }
  35.  
  36.       // Return data as JSON
  37.       echo json_encode($data);
  38.    }
  39.    catch(PDOException $e)
  40.    {
  41.       echo $e->getMessage();
  42.    }
  43.  
  44.  
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement