creare bd mysqli

<?php
$p1 = ‘Construiti o baza de date care sa contina un tabel denumit “personal” cu urmatoarea structura:
Id – autonumber , nume Varchar (15), varsta int (3)
Realizati un script php care sa permita inserarea si afisarea persoanelor in baza de date.';
$host = “localhost”;
$user = “root”;
$pass = “”;
$db = “scoala”;

$tabel = “personal”;
$conn = @new mysqli($host, $user,$pass);

if($conn -> connect_error)
{
echo “Eroare “.$conn->connect_error;
}
else
{
echo “Conectare reusita<br>”;
}
$sql_test = “SHOW DATABASES LIKE ‘{$db}'”;

if($res=$conn->query($sql_test))
{
echo $exista_bd =$res->num_rows;

if(!$exista_bd)
{
$sql = ‘CREATE DATABASE ‘. $db;

if($conn->query($sql))
{
echo “crearea bd reusita”;
}
else
{
echo $conn->error;
}
}

else
{
echo “<br>exista deja o baza de date cu numele ‘{$db}'”;

$conn -> select_db($db);

$sql = “CREATE TABLE personal (id int(6) AUTO_INCREMENT PRIMARY KEY ,
nume VARCHAR(30), varsta INT(2) NOT NULL)”;

if($conn->query($sql))
{
echo “creare tabel reusita”;
}
else
{
echo $conn->error;
}
}
}

?>

<form name=”form1″ method=”get” action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” >
<input type = “text” name=”nume”><br>
<input type = “text” name =”varsta”>
<input type = ‘submit’>
</form>

<?php

if(isset($_GET[“nume”]) && strlen($_GET[“nume”])>0 && strlen($_GET[“varsta”])>0)
{
echo “Ai introdus macar numele diferit de null<br>”;
$nume = $_GET[“nume”];
$varsta = (int)$_GET[“varsta”];

$sql = “INSERT INTO personal (nume,varsta) VALUES (‘$nume’,$varsta)”;
if($conn -> query($sql))
{
echo “adaugare reusita<br><br>”;
}
else

{
echo “Probleme la adaugare “.$conn->error;
}

}
else
{
echo “Ai grija sa fie ceva introdus la nume si varsta<br>”;
}

$sql = “SELECT nume, varsta from personal”;
if($result = $conn->query($sql))
{
while($row=$result ->fetch_assoc())
{
echo “Nume: {$row[“nume”]}, varsta {$row[“varsta”]}<br>”;
}
}

?>