Hi everyone,
I've a problem creating my table, can someone help me please?
$mydb = "dbprova";
$con = mysqli_connect("localhost", "root", "",);
$db = mysqli_select_db($con, $mydb);
if (!$db) {
echo "Database not exists";
mysqli_query($con, "CREATE DATABASE dbprova");
$newcon= mysqli_connect("localhost", "root", "", $mydb);
mysqli_query($newcon,"CREATE TABLE Employees
(employee_id INT, first_name VARCHAR(50), last_name VARCHAR(50))");
}else {
echo "Database found";
}
Table mysqli
Use PDO:
Something like this (not tested)-
Then have a look here for how to insert data etc. if you are looking at anything else, forget about it and use PDO, wherever you got that code is out of date and touch.
Something like this (not tested)-
Code: Select all
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "CREATE DATABASE IF NOT EXISTS dbprova";
$conn->exec($sql);
echo "Yay, database created";
} catch(PDOException $e) {
echo "Doh! " . $e->getMessage();
}