繁体   English   中英

如何在php中显示结果时删除此通知

[英]how to remove this notice while displaying the result in php

我已经在php中使用ODBC连接了sqlserver。 我能够连接数据库并对其进行查询,但是在结果部分中,我没有得到正确的结果。

我收到此通知:

 server connected
 Notice: Use of undefined constant CName - assumed 'CName' in      
 D:\Installations\wamp\www\connectweb\newfile.php on line 21
 Turmeric 
  Notice: Use of undefined constant CName - assumed 'CName' in    
  D:\Installations\wamp\www\connectweb\newfile.php on line 21
 Neem 
 Notice: Use of undefined constant CName - assumed 'CName' in   
 D:\Installations\wamp\www\connectweb\newfile.php on line 21
 Coriander 
  Notice: Use of undefined constant CName - assumed 'CName' in    
  D:\Installations\wamp\www\connectweb\newfile.php on line 21
 Almond 

这是我的代码:

     <?php

      $connect = odbc_connect('ServerDB','sa', 'admin');

     if (!$connect) {
    die('Something went wrong while connecting to MSSQL');
    }
      else
    echo "server connected";
      $query = "SELECT CName FROM dbo.Conc";
      $result = odbc_exec($connect, $query);

    while(odbc_fetch_row($result)){
      $name= odbc_result($result,CName);
    echo("$name  \n");
     }

   ?>

我是php的新手,我不知道自己被卡在哪里。 dbo.Conc表具有字段CName 我正在使用odbc连接到数据库。

从PHP文档:

odbc_result的第二个参数:

正在检索的字段名称。 它可以是包含所需字段的列号的整数。 或者它可以是包含字段名称的字符串。

您需要做的是:

$name= odbc_result($result,'CName');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM