Php ODBC查询';他不是和PHO一起工作的

Php ODBC查询';他不是和PHO一起工作的,php,sql,odbc,odbc-sql-server-driver,Php,Sql,Odbc,Odbc Sql Server Driver,我使用的是ODBC连接,而不是MySQL。我有一个搜索功能,我或多或少地复制了它来应用我的ODBC连接,但是它们不起作用。以下是我的代码,但连接除外: <!doctype html> <html> <title> Quoting System </title> <head> </head> <body> <form class="form" method="POST" action='try31.php'

我使用的是ODBC连接,而不是MySQL。我有一个搜索功能,我或多或少地复制了它来应用我的ODBC连接,但是它们不起作用。以下是我的代码,但连接除外:

<!doctype html>
<html>
<title> Quoting System </title>
<head>
</head>
<body>

<form class="form" method="POST" action='try31.php'>
        Quote Number <input  class="form-control" type="text" name="quote" id="quote" placeholder="Enter Quote Number">
        <br> &nbsp <input class="btn btn-default" type="submit" name="search" value="Search">
</form>     

<table>
    <tr>
        <th>Company Name</th>
        <th>Address1</th>
        <th>Address2</th>
    </tr>   

<?php

  if (!$conn){
    if (phpversion() < '4.0'){
      exit("Connection Failed: . $php_errormsg" );
    }
    else{
      exit("Connection Failed:" . odbc_errormsg() );
    }
}

if(isset($_POST['search'])){ 
$quote = $_POST['quote'];
$query = "SELECT * FROM dbo.tblVersions2 WHERE QuoteNumber LIKE '".$quote."'";
}

$result = odbc_exec($conn,$query);

    while($row =odbc_fetch_row($result)){
        echo "<tr>";
            echo "<td>".$row[2]."</td>";
            echo "<td>".$row[3]."</td>"; 
            echo "<td>".$row[4]."</td>";
        echo "</tr>";
}



// Disconnect the database from the database handle.
//odbc_close($conn);

?>
</table>
</body>
</html>

报价系统
报价编号

nbsp 公司名称 地址1 地址2
发现使用MS SQL ODBC连接时,查询语法与MySQL不同。我更改了从以下位置调用表中的列:

$result=odbc\u exec($conn,$query)

while($row=odbc\u fetch\u row($result)){
回声“;
回显“$行[2]”;
回显“$行[3]”;
回显“$行[4]”;
回声“;
}

为此:

 $result = odbc_exec($conn, $stmt);

  while (odbc_fetch_row($result)) // while there are rows
  {
     echo "<tr>";
        echo "<td>" . odbc_result($result, "CompanyName") . "</td>";
        echo "<td>" . odbc_result($result, "Address1") . "</td>";
     echo "</tr>";
  }
$result=odbc\u exec($conn,$stmt);
while(odbc_fetch_row($result))//有行时
{
回声“;
回显“.odbc_结果($result,“CompanyName”)”;
回显“.odbc_结果($result,“Address1”)”;
回声“;
}

odbc_结果函数在这里至关重要。

发现使用MS SQL odbc连接时,查询语法与MySQL不同。我更改了从以下位置调用表中的列:

$result=odbc\u exec($conn,$query)

while($row=odbc\u fetch\u row($result)){
回声“;
回显“$行[2]”;
回显“$行[3]”;
回显“$行[4]”;
回声“;
}

为此:

 $result = odbc_exec($conn, $stmt);

  while (odbc_fetch_row($result)) // while there are rows
  {
     echo "<tr>";
        echo "<td>" . odbc_result($result, "CompanyName") . "</td>";
        echo "<td>" . odbc_result($result, "Address1") . "</td>";
     echo "</tr>";
  }
$result=odbc\u exec($conn,$stmt);
while(odbc_fetch_row($result))//有行时
{
回声“;
回显“.odbc_结果($result,“CompanyName”)”;
回显“.odbc_结果($result,“Address1”)”;
回声“;
}

odbc_结果函数在这里至关重要。

它会给您带来任何错误吗?在ODBC下使用什么数据库?您尝试在哪个系统上运行它<代码>(phpversion()<'4.0')
PHP4.0是在2000年5月发布的,我真的怀疑人们在它之前是否还使用任何东西。我在你的示例中没有看到创建连接的代码嗨,它没有给出错误我的连接代码是:$conn=odbc\u connect($data\u source,$user,$password);if(!$conn){if(phpversion()<'4.0'){exit(“连接失败:.$php_errormsg”);}else{exit(“连接失败:”.odbc_errormsg());}if($conn){echo“Connected.”当我单击按钮执行查询时,表没有按预期填充,我没有收到错误。我使用的是SQL Server 2008,PHP5.3.10`表格没有按预期填充'`填充错误还是完全没有?是否会给您带来任何错误?在ODBC下使用什么数据库?您尝试在哪个系统上运行它<代码>(phpversion()<'4.0')PHP4.0是在2000年5月发布的,我真的怀疑人们在它之前是否还使用任何东西。我在你的示例中没有看到创建连接的代码嗨,它没有给出错误我的连接代码是:$conn=odbc\u connect($data\u source,$user,$password);if(!$conn){if(phpversion()<'4.0'){exit(“连接失败:.$php_errormsg”);}else{exit(“连接失败:”.odbc_errormsg());}if($conn){echo“Connected.”当我单击按钮执行查询时,表没有按预期填充,我没有收到错误。我使用的是SQLServer2008,PHP5.3.10`表格没有按预期填充'`填充错误还是完全没有?