By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,273 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,273 IT Pros & Developers. It's quick & easy.

What does the "<<<" symbol mean?

P: 14
I understand the following script is for building a database table in MySQL, but does anyone know what are the functions of the <<< in line 3 and * in lines 4 & 10?

Expand|Select|Wrap|Line Numbers
  1. <?php
  3. $sql_file=<<<SQL_FILE
  4. DROP TABLE IF EXISTS `table_name`;*
  5. CREATE TABLE IF NOT EXISTS `table_name` (
  6.   `id` int(11) NOT NULL auto_increment,
  7.   `name` varchar(250) default NULL,
  8.   `address` varchar(250) default NULL,
  9.   PRIMARY KEY  (`id`)
  10. );*
  11. SQL_FILE;
  13. ?>
Feb 19 '10 #1
Share this Question
Share on Google+
7 Replies

Expert 5K+
P: 6,050
Have a look at the heredoc/nowdoc syntax. Not sure about those asterisks though.
Feb 19 '10 #2

Expert 5K+
P: 5,058
The asterisks kind of look like either
  1. The remainder of a comment block, which somebody tried - unsuccessfully - to remove from the code, or
  2. part of a custom delimiter.
Does the SQL actually work?
Feb 19 '10 #3

P: 14
@Markus: Very cool! Never heard or seen the heredoc syntax before. Gotta love your friendly neighborhood forum. Thanks!

@Atli: Yes, this script was taken out of a working model and it's very likely the asterisk was placed intentionally as it was made by smarties over at PHP Jabbers.
Feb 19 '10 #4

P: 18
this operator is very useful when you rendering HTML with php script beacuse it doesn't requires qutoes for string like traditionally we do.

"SQL_FILE" you can use any text here in simple language its the way of starting and ending the block. when you write fist time it starts and when you put second it assumes that the block is ended.

Expand|Select|Wrap|Line Numbers
  1. $sql_file=<<<SQL_FILE
  2. <p style="color:#0000ff" onmouseover="alert('hello');">Its an example.</p>
  3. SQL_FILE;
  5. echo $sql_file;
You can see i have used both quotes (" and ' ) in my quotes. it really the fun.

sorry if the code having any minor mistake i just typed this code here i don't having any IDE and Compiler but it will work do check this up guys.....
Feb 21 '10 #5

P: 14
I finally figured out what the purpose of the * symbol was for when I stumbled upon this in the script:
Expand|Select|Wrap|Line Numbers
  1. $sql_statements = split('\;\*', $sql_file);
  2. for ($i = 0; $i < count($sql_statements) - 1; $i++) {
  3.     if (!mysql_query($sql_statements[$i], $connection)) {
  4.         $msg="Failed to submit the query: ".$sql_statements[$i];
  5.         return false;
  6.     }
  7. }
The coder used the split function to break up $sql_file into an array of individual SQL statements wherever a ;* appears. A for loop is then used to execute each statement individually and, in the event of an error, returns which key of the array caused it.

Sorry if I confused anyone from my original post!

PLEASE NOTE: The split function is deprecated!
Mar 9 '10 #6

P: 18
but you can use it and also explode function can be used.
Mar 10 '10 #7

Expert 5K+
P: 6,050
You *can* use it, but you shouldn't. That is why it's deprecated.
Mar 10 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.