Jump to content

need an understanding on this syntax


laxi

Recommended Posts

Hello ,

 

can some one breakdown and explain the below syntax

 

$sql = "INSERT INTO tutorials_tbl ". "(tutorial_title,tutorial_author, submission_date) ". "VALUES ". "('$tutorial_title','$tutorial_author','$submission_date')";

 

$sql = "CREATE TABLE tutorials_tbl( ". "tutorial_id INT NOT NULL AUTO_INCREMENT, ". "tutorial_title VARCHAR(100) NOT NULL, ". "tutorial_author VARCHAR(40) NOT NULL, ". "submission_date DATE, ". "PRIMARY KEY ( tutorial_id )); ";

 

the . and " are confusing..

Link to comment
https://forums.phpfreaks.com/topic/282375-need-an-understanding-on-this-syntax/
Share on other sites

For whatever reason the SQL query is just broken into multiple string and connected with the concatenation operator:

http://php.net/manual/en/language.operators.string.php

 

To simplify the first query, it could be written as:

 

 

<?php
$sql = "INSERT INTO tutorials_tbl (tutorial_title,tutorial_author, submission_date) VALUES ('$tutorial_title','$tutorial_author','$submission_date')";
?>

The two lines of code is assigning a SQL (cee-qual) command to a variable named $sql. Strings are contained within quotes. The dot (.) is the concatenation operator. This operator joins two strings together example

 

$var1 = 'hello';
$var2 = ' world';
echo $var1 . $var2;

The above will output the text hello world

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.