[英]Run SQL query from PHP with unique column names?
I have ran SQL query PHP lot of times. 我已经多次运行SQL查询PHP。 Usually this is what i do: 通常这是我的工作:
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$sql = "SELECT AREA,UNIT,COMPLEX,PROPERTY FROM TrimTable";
$query = sqlsrv_query($con
if ($query === false){
echo "Could not link to SQL Server";
}
while ($row = sqlsrv_fetch_array($query))
{
$AREA[] = "$row[AREA]";
$UNIT[] = "$row[UNIT]";
$COMPLEX[] = "$row[COMPLEX]";
$PROPERTY[] = "$row[PROPERTY]";
}
After this i work with my array and manipulate them way i want to. 在此之后,我使用我的数组并按我想要的方式操作它们。 This particular code on top works. 上面的特定代码有效。 But i have few columns in the table that are named unique. 但是我在表中只有几列被命名为唯一。 One of the column in the table is LOOP TYPE
. 表中的一列是LOOP TYPE
。 There is also column with ID#
. 也有ID#
列。 I looked online but could find anything. 我在网上看了一下,但什么都找不到。 How can i run query on those? 我该如何对那些查询?
UPDATE This is the code i am trying: 更新这是我正在尝试的代码:
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$sql = "SELECT AREA,UNIT,COMPLEX,`LOOP TYPE` as LOOP, PROPERTY FROM TrimTable";
$query = sqlsrv_query($conn,$sql);
if ($query === false){
echo "Could not link to SQL Server";
}
while ($row = sqlsrv_fetch_array($query))
{
print_r($row);
}
Use brackets and aliases in the query: 在查询中使用方括号和别名:
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$sql = "SELECT AREA,UNIT,COMPLEX,PROPERTY, [LOOP TYPE] as LOOP, [ID#] as ID FROM TrimTable";
$query = sqlsrv_query($conn,$sql);
if ($query === false){
echo "Could not link to SQL Server";
}
while ($row = sqlsrv_fetch_array($query))
{
$AREA[] = "$row[AREA]";
$UNIT[] = "$row[UNIT]";
$COMPLEX[] = "$row[COMPLEX]";
$PROPERTY[] = "$row[PROPERTY]";
$LOOPTYPE[] = "$row[LOOP]";
$ID[] = "$row[ID]";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.