ERROR CONNECTING TO BD PHP 7

1

I'm trying to generate a JSON file, but I'm getting ERROR 2, when I try to connect to the BD, my hosting uses PHP7, I do not know if that is influencing the error, before it worked correctly.

ERROR:

  

Opps some thing went ERROR 2

PHP File

<?php
error_reporting(0);

$hostname = "host";
$user = "user";
$password = "****";
$database = "BD";

$db = mysqli_connect($hostname, $user, $password) or die("Opps some thing went wrong");
mysqli_select_db($database, $db) or die("Opps some thing went ERROR 2");

// array for JSON response
$response = array();

// get all items from myorder table


$result = mysqli_query("SELECT * FROM escolar_tracker ") or die(mysqli_error());

if (mysqli_num_rows($result) > 0) {

    $response["rutas"] = array();

    while ($row = mysqli_fetch_array($result)) {
            // temp user array
            $item = array();
            $item["id"] = $row["id"];
            $item["ruta"] = $row["ruta"];
            $item["jornada"] = $row["jornada"];

            // push ordered items into response array
            array_push($response["rutas"], $item);
           }
      // success
     $response["success"] = 1;
}
else {
    // order is empty
      $response["success"] = 0;
      $response["message"] = "No Items Found";
}
// echoing JSON response
echo json_encode($response);


?> 
    
asked by Andres Arango 25.07.2018 в 07:14
source

1 answer

1

when you use mysqli_ * you should use the connection identifier as the first parameter in the following way

mysqli_select_db($db,$database);

the same with

mysqli_query($db,statment);
    
answered by 25.07.2018 / 07:18
source