Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function connect($host = 'localhost', $dbname = 'voip', $user = 'homestead', $password = 'secret')
- {
- try {
- $conn = new pdo("mysql:host=$host;dbname=$dbname",
- $user,
- $password,
- array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
- return $conn;
- } catch (PDOException $ex) {
- die(json_encode(array('outcome' => false, 'message' => 'Unable to connect')));
- }
- }
- $usuario = 'homestead';
- $contraseña = 'secret';
- $conn = connect('localhost', 'voip', $usuario, $contraseña);
- $conn2 = connect('localhost', 'voip2', $usuario, $contraseña);
- $sql1 = $conn->prepare("SELECT id, first_name, phone_number FROM bit_gxp_phonebook");
- $sql1->execute();
- $sql2 = $conn2->prepare("SELECT id, first_name, phone_number FROM bit_gxp_phonebook");
- $sql2->execute();
- $response1 = $sql1->fetchAll();
- $response2 = $sql2->fetchAll();
- $results = array_merge($response1, $response2);
- $json_data = [];
- for ($i = 0; $i < count($results); $i++) {
- $item = [
- 'id' => $results[$i]['id'],
- 'fist_name' => $results[$i]['first_name'],
- 'phone_number' => $results[$i]['phone_number']
- ];
- $json_data[] = $item;
- }
- print_r(json_encode($json_data));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement