How to view data from an SQL Server query using PHP?

Asked

Viewed 1,132 times

0

I’m trying to display data from a table in my database SQL Server, using the PHP, but I’m not getting it. Not error code but also returns nothing.

The code is this one:

<?php
$serverName = "MIRCIA-PC\PRIMAVERA";
$resultadoectionInfo = array( "Database"=>"PRICVE", "UID"=>"sa", "PWD"=>"INFODMIDMI99" );
$resultado = sqlsrv_connect( $serverName, $resultadoectionInfo);
if( $resultado === false ) {
  die( print_r( sqlsrv_errors(), true));
}

$query=sqlsrv_query($resultado,"SELECT SELECT Artigo, Descricao, STKMaximo, STKMinimo, STKActual FROM Artigo");

if($query){
  while($row=sqlsrv_fetch_array($query)){
    $flag[]=$row;
  }
  print (json_encode($flag));
}
sqlsrv_close($resultado);
?>
  • has two SELECT in the query, leaves only one

  • If you use the same SQL statement in the database is returned something ? What’s in your $query with the var_dump ?

1 answer

0

When you do Database Select you have the structure wrong because you are repeating select

How your:

$query=sqlsrv_query($result,"SELECT SELECT Article, Description, Stkmaximo, Stkminimo, Stkactual FROM Article");

As it should be :

$query=sqlsrv_query($result,"SELECT Article, Description, Stkmaximo, Stkminimo, Stkactual FROM Article");

  • Yes, thank you very much, I hadn’t even noticed that the syntax structure was wrong. Thank you for the correction. But I’ve fixed it, and yet, it still doesn’t return the list of products contained in my comic

  • Try this - $query=sqlsrv_query($result,"SELECT 'Article', 'Description', 'Stkmaximo', 'Stkminimo', 'Stkactual' FROM 'Article'");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.