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
ewfile.php on line 21
Turmeric
Notice: Use of undefined constant CName - assumed 'CName' in
D:\Installations\wamp\www\connectweb
ewfile.php on line 21
Neem
Notice: Use of undefined constant CName - assumed 'CName' in
D:\Installations\wamp\www\connectweb
ewfile.php on line 21
Coriander
Notice: Use of undefined constant CName - assumed 'CName' in
D:\Installations\wamp\www\connectweb
ewfile.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
");
}
?>
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.