简体   繁体   English

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

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

I have connected sqlserver using ODBC in php. 我已经在php中使用ODBC连接了sqlserver。 I'm able to connect the database and query it, but in the result part I'm not getting proper results. 我能够连接数据库并对其进行查询,但是在结果部分中,我没有得到正确的结果。

I'm getting this notice: 我收到此通知:

 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 

This is my code: 这是我的代码:

     <?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");
     }

   ?>

I'm new to php and I don't know where I'm stuck. 我是php的新手,我不知道自己被卡在哪里。 The dbo.Conc table has a field CName . dbo.Conc表具有字段CName I'm connecting to the database using odbc. 我正在使用odbc连接到数据库。

From PHP docs: 从PHP文档:

The second argument for odbc_result: odbc_result的第二个参数:

The field name being retrieved. 正在检索的字段名称。 It can either be an integer containing the column number of the field you want; 它可以是包含所需字段的列号的整数。 or it can be a string containing the name of the field. 或者它可以是包含字段名称的字符串。

What you need to do is this: 您需要做的是:

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

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

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