Jump to content

need an understanding on this syntax


laxi
Go to solution Solved by cyberRobot,

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
Share on other sites

  • Solution

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')";
?>
Link to comment
Share on other sites

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

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.