Jump to content

simple sql insert not working


scottybwoy

Recommended Posts

Is it possible to use <<<EOD on long string queries in variables.

 

This code isn't working :

<?php

mysql_connect('server', 'user', 'pass') or trigger_error("Could not Connect", E_USER_NOTICE);

mysql_select_db('database') or trigger_error("Could not Connect to DB", E_USER_NOTICE);

$sql = <<<EOD
drop table if exists configuration;
create table configuration (
configuration_id int(11) not null auto_increment,
configuration_title varchar(255) not null ,
configuration_key varchar(255) not null ,
configuration_value varchar(255) not null ,
configuration_description varchar(255) not null ,
configuration_group_id int(11) default '0' not null ,
sort_order int(5) ,
last_modified datetime ,
date_added datetime default '0000-00-00 00:00:00' not null ,
use_function varchar(255) ,
set_function varchar(255) ,
PRIMARY KEY (configuration_id)
);

insert into configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) values ('1', 'Store Name', 'STORE_NAME', 'KlickShopping', 'The name of my store', '1', '1', NULL, '2008-05-14 03:38:42', NULL, NULL);
EOD;
mysql_query($sql) or trigger_error("Did not restore");

?>

 

How should this be written?

Link to comment
Share on other sites

try.

<?php

mysql_connect('server', 'user', 'pass') or trigger_error("Could not Connect", E_USER_NOTICE);

mysql_select_db('database') or trigger_error("Could not Connect to DB", E_USER_NOTICE);

$sql = "
create table configuration (
   configuration_id int(11) not null auto_increment,
   configuration_title varchar(255) not null ,
   configuration_key varchar(255) not null ,
   configuration_value varchar(255) not null ,
   configuration_description varchar(255) not null ,
   configuration_group_id int(11) default '0' not null ,
   sort_order int(5) ,
   last_modified datetime ,
   date_added datetime default '0000-00-00 00:00:00' not null ,
   use_function varchar(255) ,
   set_function varchar(255) ,
   PRIMARY KEY (configuration_id)
);";


mysql_query($sql) or trigger_error("Did not restore");

$sql="insert into configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) values ('1', 'Store Name', 'STORE_NAME', 'KlickShopping', 'The name of my store', '1', '1', NULL, '2008-05-14 03:38:42', NULL, NULL)";

mysql_query($sql) or trigger_error("Did not restore");

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.