0
I 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
– Leonardo Barros
It is the same select shown inside the $sql variable
– Sarah Tavares
@Leonardobarros do you have any idea why it’s not working?
– Sarah Tavares
SQL Profile is showing exactly what should be run?
– Onaiggac
yes @Onaiggac, is showing exactly what should be run. I will edit the question by posting the query to sql server
– Sarah Tavares
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
– Sarah Tavares
It’s different, one has
DESCRICAO
the otherGRUPO_DESCRICAO
– Leonardo Barros
ah yes it’s all GRUPO_DESCRICAO, it was my mistake to post @Leonardobarros
– Sarah Tavares
How you assign the like value?
– Leonardo Barros
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
– Sarah Tavares
It doesn’t make much sense this DISTINCT if you do a GROUP BY by the same field.
– anonimo
@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
– Sarah Tavares
Let’s go continue this discussion in chat.
– Leonardo Barros
"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?
– Ronaldo Araújo Alves
No... @Ronaldoaraújoalves. There are times they return with days 21,02,14, 27.. varies.
– Sarah Tavares
@Ronaldoaraújoalves pq the idea days less than 13 ?
– Sarah Tavares
In case the date is, for example, 06/20/2019 and the system is trying to convert the "20" as month.
– Ronaldo Araújo Alves