Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- @header('Content-type: application/json');
- header('Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept"');
- header("Access-Control-Allow-Origin: *", false);
- // Define database connection parameters
- $hn = 'localhost';
- $un = 'root';
- $pwd = '';
- $db = 'karina';
- $cs = 'utf8';
- $cpf=$_GET["cpf"];
- // Set up the PDO parameters
- $dsn = "mysql:host=" . $hn . ";port=3306;dbname=" . $db . ";charset=" . $cs;
- $opt = array(
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
- PDO::ATTR_EMULATE_PREPARES => false,
- );
- // Create a PDO instance (connect to the database)
- $pdo = new PDO($dsn, $un, $pwd, $opt);
- $data = array();
- // Attempt to query database table and retrieve data
- try {
- $stmt = $pdo->query("SELECT id_paciente, nome, cpf, idade, peso, altura, cartao_sus, endereco, telefone FROM paciente WHERE cpf = '$cpf'");
- while($row = $stmt->fetch(PDO::FETCH_OBJ))
- {
- // Assign each row of data to associative array
- $data[] = $row;
- }
- // Return data as JSON
- echo json_encode($data);
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement