scottybwoy Posted March 20, 2009 Share Posted March 20, 2009 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? Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 20, 2009 Share Posted March 20, 2009 Hi You have inverted commas around values for numeric fields. Also you do not need to specify configuration_id as it is an autonumber. Either leave configuration_id and its value out or use NULL for its value. All the best Keith Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 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"); ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 20, 2009 Share Posted March 20, 2009 How should this be written? As three separate queries - mysql_query() sends a unique query (multiple queries are not supported) or use the mysqli functions, which do support multiple queries using mysqli_multi_query(). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.