简体   繁体   中英

how to remove this notice while displaying the result in php

I have connected sqlserver using ODBC in php. 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. The dbo.Conc table has a field CName . I'm connecting to the database using odbc.

From PHP docs:

The second argument for 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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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