Why give space after end of query statement?

I know title makes you confused, kindly check the code below

$sql = “CREATE TABLE student (ID INT NOT NULL AUTO_INCREMENT, name VARCHAR(40), last_name VARCHAR(40) NOT NULL, email VARCHAR(40) NOT NULL, PRIMARY KEY(ID)) ”;
// why we give the double apostrophe space " after the bracket close, is it required, sometimes the code works and sometimes now.

I’d be interested in seeing an example of a query where the presence or absence of a space makes a difference in whether or not it works.

I have seen a lot of code that was broken due to getting lost while mixing single and double quotes, complex concatenation etc. but never because of an extra space, which AFAIK is never needed but may be there to improve readability.

no, it isn’t

1 Like

It might be where you saw a space at the end was when the query was being built, in which case a space would need to be somewhere. eg.

// code that sets the field name 
$query = "SELECT $somefield "; 
// code that sets the table name 
$query .= "FROM $sometable ";
// more code 
$query .= "WHERE ...
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.