-4

Problem

By right CREATE TABLE IF NOT EXISTS $table query should be working since it work in live project. However it's not able to create new table after setup.

I have checked mysql error log, error do not exist. Not able to find mysql error - ( refer How to see log files in MySQL? )

My Setup

  • MySQL Version 5.5.0

  • MySQL charset: UTF-8 Unicode (utf8)

  • Apache/2.4.23 (Unix) PHP/5.6.25

  • MySQL client version: mysqlnd 5.0.11-dev - 20120503 - $Id$

  • phpMyAdmin Version information: 3.4.6

Solution : Do not include sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO$ in my.cnf file. One of the command here cause problem, but at last it's work after removed it.

Community
  • 1
  • 1
Txuver Jhi Wei
  • 318
  • 2
  • 5
  • 17
  • 1
    How do you execute this query? What is the value of `$table`? – Qirel Dec 15 '16 at 13:17
  • 3
    there isn't enough code to support the question, this in regards to "php" - check for errors via php and the query. You may be trying to create the same table. – Funk Forty Niner Dec 15 '16 at 13:17
  • Please add your php code. We cannot help without that. – arkascha Dec 15 '16 at 13:19
  • Fred-ii- there is no exact same table name. Because I will check whether table name exist in database. Qirel $table is table name I want to create – Txuver Jhi Wei Dec 15 '16 at 13:24
  • @arkascha I guess it's not code problem. Since it work in live. Other developer working as well. I just want to know anyone face same problem with me. Or I may misconfigure something. – Txuver Jhi Wei Dec 15 '16 at 13:27
  • Then this question makes little sense, sorry. It is pretty obvious that the MySQL feature `CREATE TABLE IF NOT EXISTS` _does_ work, otherwise the Internet would be _full_ of bug reports and questions. – arkascha Dec 15 '16 at 13:33

2 Answers2

0

$table is table name I want to create

I believe then your SQL statement would be like

CREATE TABLE IF NOT EXISTS table1

Well that's total wrong cause you are completely missing the table definition. Means the column names, their datatype and size at bare minuimum even if you don't want to create any constraint right away.

Rahul
  • 76,197
  • 13
  • 71
  • 125
0

You can not create table without column.

Try this syntax:

CREATE TABLE IF NOT EXISTS `$table` (
  `id` int(11) NOT NULL
);

This query successfully created table "$table".

Anshul
  • 116
  • 1
  • 10