1
votes

I have a php file with the proper information, and I cannot figure out why I cannot make an ODBC connection to my SQL Database?

I have two files and am trying to create a simple webpage that is connected to my database.

First File (odbc_vertices.php):

   <?php

   //creates an odbc connection and stores it in $odbc variable
   $odbc = odbc_connect ('VERTICES', 'correctusername','correctpassword') or die ( "Could Not Connect to ODBC Database!" );

   ?>

Second File (phptest.php):

   <html>

   <head>
   <title></title>
   </head>

   <body>

   <?php


   include 'odbc_vertices.php'; 
   ?>


  <select name='vndr'>
  <option selected>
  <?php
     $query =odbc_exec($odbc_vertices,"SELECT * FROM tblOrder where Receive=No Order  BY TapeType") or die (odbc_errormsg());
            while ($row=odbc_fetch_array($query))
                   {


                    echo "<option value='".$row['VendorName']."'>".strtoupper($row ['VendorName'])."</option>";

                   }
   ?>
      </select>
      <INPUT TYPE=HIDDEN NAME='nam' SIZE='2'>


      <?php

   odbc_close($odbc_vertices);
   ?>

   </body>

   </html>

However I'm receiving this error when I go to test the page:

Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'., SQL state 28000 in SQLConnect in odbc_vertices.php on line 4 Could Not Connect to ODBC Database!

I'm trying to figure out what should be changed in the odbc_vertices.php file for the connection to be successful. Any help would be appreciated

1

1 Answers

0
votes

My thought would be that the ODBC DSN "Vertices" is setup incorrectly on the machine itself.

My suggestion would be to try a code similar to:

$conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=YOURSERVERDatabase=DATABASE", 'correctusername','correctpassword');
$query = odbc_exec($conn,"SELECT * FROM tblOrder ...") or die (odbc_errormsg());

Other connection strings, if the above fails, can be found at http://www.connectionstrings.com/sql-server/

My other thought that the user permissions inside the database are not correctly setup to allow correctusername to access the database