First let's go to concepts.
You are exiting the procedural mode from mysqli_query
to object-oriented. I commented on this case briefly in this question .
The problem is that you are still messing with procedural and object-oriented when working with mysqli_query
.
How would it be to work with 'object-oriented mysqli_query:
Connection (Not that yours is wrong)
// Conecta ao banco de dados
$mysqli = new mysqli('127.0.0.1', 'usuario', 'senha', 'banco');
Valuing the connection
// Verifica se ocorreu algum erro
if (mysqli_connect_errno()) {
die('Não foi possível conectar-se ao banco de dados: ' .
mysqli_connect_error());
exit();
}
Try using the Prepared Statements . Make your life easier
/* Prepared statement, Primeiro parte prepare o sql.
Verifique se não ocorreu erro */
if (!($stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (?)"))) {
echo "Falha no Prepare: (" . $mysqli->errno . ") " . $mysqli->error;
}
// Segunda parte passe os parâmetros e execute a query
$id = 1;
if (!$stmt->bind_param("i", $id)) {
echo "Falha no bind_param: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
echo "Falha ao executar a query: (" . $stmt->errno . ") " . $stmt->error;
}
Another example . Otherwise, avoid using @
in database queries or anywhere in your code. Omitting errors and warnings only hinders you from producing good code.
I hope that helps you.