Error creating table in MySQL using PHP -


i writing php script create database , use create table. assume using correct mysql syntax yet faing error - error creating table: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'use website; create table users ( id int(11) unsigned auto_increment pri' @ line 2

here php script - create_db.php

<?php  function create_database($hostname, $username, $password) {  $h = $hostname; $u = $username; $p = $password;  $conn = new mysqli($h, $u, $p); // check connection if ($conn->connect_error) {     die("connection failed: " . $conn->connect_error); }  $sql = "create database website;         use website;         create table users (         id int(11) unsigned auto_increment primary key,         firstname varchar(255) not null,         lastname varchar(255) not null,         email varchar(255) not null,         password varchar(255) not null,         hash varchar(255) not null,         forgot_password_hash varchar(255) not null,         status enum('1', '0') not null         );";  if ($conn->query($sql) === true) { echo "table users created successfully"; } else {     echo "error creating table: " . $conn->error; }  $conn->close(); }  create_database('localhost', 'root', 'root');  ?> 

you have use multi_query() instead query()

$conn->multi_query($query) 

see more details multi_query here: http://php.net/manual/en/mysqli.multi-query.php


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -