2
I’m getting the error while trying to connect to the database.
Configuration.php
class Connection {
private static $connection = null;
public static get() {
if (self::$connection == null) { self::$connection = mysqli_connect("mysql.uhserver.com", "user", "passw","db" ); }
return self::$connection;
}
}
page php
header("content-type:application/json");
require_once '../includes/configuration.php';
$result= mysqli_query(Connection::get(),"SELECT Id, Titulo, Descricao, date_format(DataEvento, '%d/%m/%Y') AS DataEvento FROM agenda WHERE DATAEVENTO >= NOW() ORDER BY DATACADASTRO" ) or die(mysqli_error());
Error
syntax error, Unexpected 'get' (T_STRING), expecting variable (T_VARIABLE)
Just one detail: he’s using the API
mysqli
, naymysql
, then there would be no need to exchange for PDO without need. Just commenting, given its addendum at the end of the answer.– Woss
Dear gmsantos your answer this very correct +1 is already guaranteed, but I have to agree with @Andersoncarloswoss about the end of the answer, has no real advantage between both Apis, so much so that the argument is to migrate from easier bank, this is a mistake, because the syntax of banks are different, perhaps in a ORM system (written in PDO and without queries) it would be advantageous, but woe the own ORM internally it is who would define it. The link of the article you quoted is good, but it is not the case here and neither reinforces anything about the use of PDO > mysqli.
– Guilherme Nascimento
I didn’t realize it was
mysqli_*
, but still prefer to recommend PDO because it abstracts the API from the database communication and has an object-oriented approach. Yes, you can use object-oriented mysqli as well, but it’s still an implementation tied to a specific database.– gmsantos
There may be queries that work on one DB or another, but SQL is a default and most queries if written correctly with what it says the specification will work smoothly.
– gmsantos