Php does not connect to the database (MySQL)

2
So I recently started with php and I tried to make a simple crud with php + mysql but I had a problem that I believe to be connecting to mysql. when loading the action in html, the page is left blank. It does not return error or insert into the database. Here is the script below:

       <form class="central text" name="cadastro" method="post" action="cadastro.php">
        <div>
            <h2>Dados Pessoais</h2>
            <p>Primeiro Nome</br><input type="text" name="primeiroNome"></p>
            <p>Sobrenome</br><input type="text" name="sobrenome"></p>
            <p>Nascimento</br><input type="date" name="nascimento"></p>
            <p>Nacionalidade</br><input type="text" name="nacionalidade"></p>
        </div>
        <input name="salvar" type="submit" value="Salvar">
    </form>

The simple test, just to know if it is connecting. You do not have the insert query in the database because you do not even have to pass that connection line:

<?php

$conexao = mysql_connect ("localhost", "root", "") 
echo "Conectado!";
    or die("Não conectado ao banco! Erro: ".mysql_error());
?>

Thanks to anyone who can help. For the record: 1-Yes, to get here and ask someone, I researched a lot! 2-I'm using Linux (LAMP)

    
asked by anonymous 10.07.2016 / 05:48

1 answer

1

<?php
$servidor = 'localhost';
$usuario = 'root';
$senha = '';
$banco = 'test';
$con = new mysqli($servidor, $usuario, $senha, $banco);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}else{
echo "Conectou !!";
} 
?>

See if it works, anything says agent adjusts ...

    
10.07.2016 / 06:06