SQL query attribute before column name

I have an INSERT statement in a PHP file where at-sign (@) are found before the column name.

@ field1, @ Field2,

This is a MySQL database. What does the at sign mean?

Edit:
There is no SET @field1 := 'test' in the PHP script. The PHP script reads csv and puts the data in a table. Could this be misused as a comment function?

 <?php $typo_db_username = 'xyz'; // Modified or inserted by TYPO3 Install Tool. $typo_db_password = 'xyz'; // Modified or inserted by TYPO3 Install Tool. // login $_SESSION['host'] = "localhost"; $_SESSION['port'] = "3306"; $_SESSION['user'] = $typo_db_username; $_SESSION['password'] = $typo_db_password; $_SESSION['dbname'] = "database"; $cxn = mysqli_connect($_SESSION['host'], $_SESSION['user'], $_SESSION['password'], $_SESSION['dbname'], $_SESSION['port']) or die ("SQL Error:" . mysqli_connect_error() ); mysqli_query($cxn, "SET NAMES utf8"); $sqltrunc = "TRUNCATE TABLE tablename"; $resulttrunc = mysqli_query($cxn,$sqltrunc) or die ("Couldn't execute query: ".mysqli_error($cxn)); $sql1 = " LOAD DATA LOCAL INFILE 'import.csv' REPLACE INTO TABLE tablename FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\"' IGNORE 1 LINES ( `normalField`, @field1, @field2, `normalField2`, @field3, @field4 )"; $result1 = mysqli_query($cxn,$sql1) or die ("Couldn't execute query: " . mysqli_error($cxn)); ?>' 

Decision

Finally, I get it! The @ field is used as a dummy to skip a column in the csv file. See http://www.php-resource.de/forum/showthread/t-97082.html http://dev.mysql.com/doc/refman/5.0/en/load-data.html
+8
sql mysql symbol at-command
source share
1 answer

The @ sign is a variable in SQL.

In MySQL, it is used to store values ​​between successive runs of a query or to transfer data between two different queries.

Example

Data transfer between two requests

 SELECT @biggest:= MAX(field1) FROM atable; SELECT * FROM bigger_table WHERE field1 > @biggest; 

Another use relates to ranking, in which MySQL does not have built-in support.

Save value for sequential query runs

 INSERT INTO table2 SELECT @rank := @rank + 1, table1.* FROM table1 JOIN( SELECT @rank := 0 ) AS init ORDER BY number_of_users DESC 

Please note that for this to work, the order in which the lines are processed in the request must be fixed, it is easy to get it wrong.

Cm:
http://dev.mysql.com/doc/refman/5.0/en/user-variables.html
mysql sort order definition
http://www.xaprb.com/blog/2006/12/15/advanced-mysql-user-variable-techniques/

UPDATE
This code will never work.
You have just opened a connection before and do not install @fields anywhere.
Therefore, they currently contain null values.
Upstairs you cannot use @vars to denote field names , you can only use @vars values ​​for values.

 $sql1 = " LOAD DATA LOCAL INFILE 'import.csv' REPLACE INTO TABLE tablename FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\"' IGNORE 1 LINES (`normalField`, @field1, @field2, `normalField2`, @field3, @field4)"; 
+8
source share

All Articles