I can not access my database

1

I have the following problem, I am trying to change the year of the dates I have in my database, and for this I am using:

mysqli_fetch_row

But I am not succeeding, returns always fails. I also made a connection to the database and apparently it is working because it does not return with error. I really appreciate any kind of help. If the question is not clear enough, please request that I make the necessary amendments. Thanks

Code:

 <?php 
 //Create a database connection
     $dbhost = "localhost";
     $dbuser = "root";
     $dbpass = "";
     $dbname = "bd-aircaw-1";
     $connection =mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
 // Check connection
 if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }

    $query = "SELECT * ";
    $query .= "FROM voo ";
    $query .= "WHERE DataPartida = 2014-11-01 18:00:00";

    $result = mysqli_query($connection, $query);
    if(!$result) {
        die ("Database query failed.");
    }

    while($row = mysqli_fetch_row($result)){
        var_dump($row);
        echo "<hr />";
    }
    
asked by anonymous 11.05.2015 / 18:03

2 answers

1

Your connection is incomplete, see the example of W3Schools : $con=mysqli_connect("localhost","my_user","my_password","my_db");

You should use quotation marks to search for datas and strings on BD :

'$query .= "WHERE DataPartida = \"2014-11-01 18:00:00\"";'
    
11.05.2015 / 18:05
2

Your problem code:

$query .= "WHERE DataPartida = 2014-11-01 18:00:00";

Add single quotes or double quotation marks with escapes:

$query .= "WHERE DataPartida = '2014-11-01 18:00:00'";
ou
$query .= "WHERE DataPartida = \"2014-11-01 18:00:00\"";
    
11.05.2015 / 23:00