3 Replies - 1026 Views - Last Post: 13 August 2012 - 10:36 PM Rate Topic: -----

#1 EmiT FliX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 05-August 12

If "CREATE" database is true than "CREATE TABLE" is fo

Posted 13 August 2012 - 02:17 AM

Hey,
So, reading up on MySQLI (YES I FEEL LIKE A BAWS!), and only just found out you can create a database/tables in php using MySQLI code...so here's my question
If my database is created have the page refresh than create the tables once the database is confirmed...

Here's my create_database.php
<?php
// connect to the MySQL server
$conn = new mysqli('localhost', 'root', '');

// check connection
if (mysqli_connect_errno()) {
  exit('Connect failed: '. mysqli_connect_error());
}

// sql query with CREATE DATABASE
$sql = "CREATE DATABASE `Users` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";

// Performs the $sql query on the server to create the database
if ($conn->query($sql) === TRUE) {
  echo 'Database "tests" successfully created';
}
else {
 echo 'Error: '. $conn->error;
}

$conn->close();
?>



Is This A Good Question/Topic? 0
  • +

Replies To: If "CREATE" database is true than "CREATE TABLE" is fo

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3550
  • View blog
  • Posts: 10,319
  • Joined: 08-June 10

Re: If "CREATE" database is true than "CREATE TABLE" is fo

Posted 13 August 2012 - 04:49 AM

you can also create all (the DB and the tables) in one swoop using a transaction. should that fail, roll back, otherwise commit the change.
Was This Post Helpful? 1
  • +
  • -

#3 EmiT FliX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 05-August 12

Re: If "CREATE" database is true than "CREATE TABLE" is fo

Posted 13 August 2012 - 04:43 PM

So instead of going

create database -> automatic direct to create tables

It can be this:

Create Database and Create Tables - > link to login.php
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3550
  • View blog
  • Posts: 10,319
  • Joined: 08-June 10

Re: If "CREATE" database is true than "CREATE TABLE" is fo

Posted 13 August 2012 - 10:36 PM

that would be a possibility.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1