0

Ok, so I have this code:

    <?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpwd = 'ALLO';
$dbname = 'test';
$conn = mysqli_connect($dbhost, $dbuser, $dbpwd, $dbname);


if(! $conn )
{
  die("\nconn: $conn \nCould not connect: " . mysqli_error($conn));
}
echo "\n";







$createtab="CREATE TABLE People(FirstName CHAR(30),LastName CHAR(30),Age INT)";

// Execute query
if (mysqli_query($conn,$createtab))
  {
  echo "Table created successfully";
  }
else
  {
  echo "Error creating table: " . mysqli_error($conn);
  }

echo "\n";




mysqli_query($conn,"INSERT INTO People (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin',35)");

mysqli_query($conn,"INSERT INTO People (FirstName, LastName, Age)
VALUES ('Glenn', 'Quagmire',33)");






mysqli_close($conn)
?>

When I run the php script, it runs fine.

However, I can't find the table in mysql workbench.

I refreshed many times.

https://i.stack.imgur.com/uX1sQ.png https://i.stack.imgur.com/iEXqT.png

Mike Ribeiro
  • 3
  • 1
  • 3

1 Answers1

0

See if this gives you any results:

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='People'

if not,Create a db before any tables or ,judging from your screenshot just add a USE test in your code.

$createdb="USE test";

// Execute query
if (mysqli_query($conn,$createdb))
 {
  echo "Db selected";
 }
else
 {
  echo "Error selecting db: " . mysqli_error($conn);
 }
Mihai
  • 26,325
  • 7
  • 66
  • 81