-1

I'm having trouble displaying SQL Server 2016 database parameters, the problem is in this line:

$stmt = $con->prepare($query);

Query:

$query = "SELECT Nome, Pais, Estado FROM [dbo].[Table] WHERE Nome = ? LIMIT 0,1";

Database:

<?php $host = "XXX"; $user = "XXX"; $password = "XXX"; $database = "XXX"; $conn = array("Database" => $database, "UID" => $user, "PWD" => $password); $con = sqlsrv_connect($host, $conn); if( !$con ) { print 'Connection could not be established.'; die( print_r( sqlsrv_errors(), true)); } ?>
Dale K
  • 25,246
  • 15
  • 42
  • 71
  • Can you please check `errno` and `error` for `$con`? – csabinho Oct 10 '19 at 22:17
  • Possible duplicate of [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – GMB Oct 10 '19 at 23:10

1 Answers1

0

The query

$query = "SELECT Nome, Pais, Estado FROM [dbo].[Table] WHERE Nome = ? LIMIT 0,1";

isn't going to work on SQL Server. LIMIT is a MySQL (and others) operator. Instead you need to do something like this:

$query = "SELECT Nome, Pais, Estado FROM [dbo].[Table] WHERE Nome = ? ORDER BY Nome OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY";
Greg Low
  • 1,526
  • 1
  • 4
  • 4