tags:

views:

121

answers:

6

What does the following line mean, particularly the operator .= ?

$query .= "UPDATE authors SET author=LOWER(author) WHERE id=2;";

in the code

<?php

$conn = pg_pconnect("dbname=publisher");

// these statements will be executed as one transaction

$query = "UPDATE authors SET author=UPPER(author) WHERE id=1;";
$query .= "UPDATE authors SET author=LOWER(author) WHERE id=2;";

pg_query($conn, $query);

?>

It seems to make some sort of array such that the last command processes first the first query and then the second.

+5  A: 

This is the concatenate assignment operator. It will concatenate or add to the end of the string. So:

$a = "Hi!";

$a .= " I";
$a .= " love";
$a .= " StackOverflow";
$a .= " a";
$a .= " lot";

echo $a; // echos "Hi! I love StackOverflow a lot"

In your case

$query = "UPDATE authors SET author=UPPER(author) WHERE id=1;";
$query .= "UPDATE authors SET author=LOWER(author) WHERE id=2;";
echo $query; 
/* echos "UPDATE authors SET author=UPPER(author) WHERE id=1; UPDATE authors SET author=LOWER(author) WHERE id=2; */
Chacha102
A: 

Concatentates the string... so $query becomes:

"UPDATE authors SET author=UPPER(author) WHERE id=1;UPDATE authors SET author=LOWER(author) WHERE id=2;"

jsight
+2  A: 

It means $query = $query . "UPDATE authors SET author=LOWER(author) WHERE id=2;";

So it appends the String to the Query Variable.

Henrik P. Hessel
A: 

it separates the updates with ; and executes both of them

Galen
A: 

.= simply means "append". This

$query = "UPDATE authors SET author=UPPER(author) WHERE id=1;";
$query .= "UPDATE authors SET author=LOWER(author) WHERE id=2;";

…results in

$query == "UPDATE authors SET author=UPPER(author) WHERE id=1;UPDATE authors SET author=LOWER(author) WHERE id=2;"
Sidnicious
+1  A: 
Bruno Reis