Question

I already tried with/without the quotes, with/without the or exit(), I tripple checked I am connected to the DB correctly.

Edit: Now I am getting my own custom error:

$username="user";
$password="*****";
$hostname="localhost";

mysql_connect($hostname,$username,$password) or exit("Error: @mysql_connect.");
mysql_select_db("test") or exit("Error: @mysql_select_db.");

mysql_query("CREATE TABLE propiedades(
'id' SMALLINT NOT NULL AUTO_INCREMENT,
'colonia' VARCHAR(35),
'zona' VARCHAR(35),
'precio' DECIMAL(9,2),
'usd' BOOLEAN,
'tipo' TINYINT,
'venta' BOOLEAN,
'recamaras' TINYINT,
'banos' TINYINT,
'mbanos' TINYINT,
'plantas' TINYINT,
'construccion' SMALLINT,
'terreno' SMALLINT,
'edad' TINYINT,
'uploaded' TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
'updated' TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
'ocultar' BOOLEAN NOT NULL DEFAULT 0,
PRIMARY KEY (id))") or exit("Error: @mysql_query CREATE TABLE.");

My code is throwing "Error: @mysql_query CREATE TABLE."

Était-ce utile?

La solution

I didn't check for your query's syntax, I'm just demonstrating how it should be done. As mario in a comment above said, you can't feed pure mysql code into php and expect it to work... to do so you need to use mysql api or pdo.

$sql = '
    CREATE TABLE propiedades(
    `id` SMALLINT NOT NULL AUTO_INCREMENT,
    `colonia` VARCHAR(35),
    `zona` VARCHAR(35),
    `precio` DECIMAL(9,2),
    `usd` BOOLEAN,
    `tipo` TINYINT,
    `venta` BOOLEAN,
    `recamaras` TINYINT,
    `banos` TINYINT,
    `mbanos` TINYINT,
    `plantas` TINYINT,
    `construccion` SMALLINT,
    `terreno` SMALLINT,
    `edad` TINYINT,
    `uploaded` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    `updated` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    `ocultar` BOOLEAN NOT NULL DEFAULT 0,
    PRIMARY KEY (id))';

$result = mysql_query($sql);

if (!$result)
    exit("Error: @CREATE TABLE.");

Autres conseils

Well, you should probably put your whole SQL code into mysql_query function

as an argument:

$result = mysql_query('CREATE TABLE propiedades(
    "id" SMALLINT NOT NULL AUTO_INCREMENT,
    "colonia" VARCHAR(35),
    "zona" VARCHAR(35),
    "precio" DECIMAL(9,2),
    "usd" BOOLEAN,
    "tipo" TINYINT,
    "venta" BOOLEAN,
    "recamaras" TINYINT,
    "banos" TINYINT,
    "mbanos" TINYINT,
    "plantas" TINYINT,
    "construccion" SMALLINT,
    "terreno" SMALLINT,
    "edad" TINYINT,
    "uploaded" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    "updated" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    "ocultar" BOOLEAN NOT NULL DEFAULT 0,
    PRIMARY KEY (id))');
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top