Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt

Heredoc is one of the useful solution to secure better readability when we code SQL Query in PHP


Below is an example using Heredoc for SQL Query in PHP

Code Block
	$sql = <<<SQL
		select *
		from class
		where grade>5
	SQL;


Below is another example using Heredoc with variables for SQL Query in PHP

Code Block
	$sql = <<<SQL
		insert into celebrity( id, name, gender, year, month, day, hour, lunar, img, thumbnail, created_at, updated_at, active)
		values('{$id}', '{$name}', '{$gender}', {$yy}, {$mm}, {$dd}, {$hh}, '{$lunar}', '{$new_img_filename}', '{$new_thumbnail_filename}', '{$now}', '{$now}', true)
	SQL;

...