Why doesn’t my select return in PHP?

Asked

Viewed 105 times

0

inserir a descrição da imagem aquiI have a PHP query which is as follows:

<?php
$serverName = "servidor";
$connectionInfo = array( "Database"=>"banco", "UID"=>"user", "PWD"=>"senha");
$conn = sqlsrv_connect( $serverName, $connectionInfo );
if( $conn === false ) {
    die( print_r( sqlsrv_errors(), true));
}

$sql = "SELECT  distinct  CONVERT(date, colunadata,103)as data FROM LISTA2 WHERE colunadata IS NOT NULL and DESCRICAO like '%valor%' GROUP BY CONVERT(date,colunadata,103)";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
     $dateString = $row['data']->format('d/m');
      echo $dateString."<br />";
}

sqlsrv_free_stmt( $stmt);

?>

It happens that depending on the value I put in the WHERE it works and prints on the screen the result as the "ECHO" defined above. However I put this select inside a query in SQL SERVER and returns value! Why not return some values in PHP ?

  • Put the query made in SQL SERVER in the question

  • It is the same select shown inside the $sql variable

  • @Leonardobarros do you have any idea why it’s not working?

  • SQL Profile is showing exactly what should be run?

  • yes @Onaiggac, is showing exactly what should be run. I will edit the question by posting the query to sql server

  • the query in sql server runs and returns the value correctly but when I put the same query in PHP it does not return any value, the screen turns white simply

  • It’s different, one has DESCRICAO the other GRUPO_DESCRICAO

  • ah yes it’s all GRUPO_DESCRICAO, it was my mistake to post @Leonardobarros

  • How you assign the like value?

  • the select would be "SELECT distinct CONVERT(date, colonnade,103)as data FROM LISTA2 WHERE colonnade IS NOT NULL and GRUPO_DESCRICAO like '%209524 | 2.8 GR. CARBON FIBER ROLLER Ø146%' GROUP BY CONVERT(date,103)". The value is actually this string

  • It doesn’t make much sense this DISTINCT if you do a GROUP BY by the same field.

  • @anonimo yes... even taking out GROUP BY the return is the same! And in the query in sql server works as can be seen in the image

  • "depending on the value I put in WHERE it works and prints on the screen the result". By chance these times it works has some relation with the dates whose DAYS are less than 13?

  • No... @Ronaldoaraújoalves. There are times they return with days 21,02,14, 27.. varies.

  • @Ronaldoaraújoalves pq the idea days less than 13 ?

  • In case the date is, for example, 06/20/2019 and the system is trying to convert the "20" as month.

Show 12 more comments
No answers

Browser other questions tagged

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