0
I am starting in PHP together with SQL Server 2008.
The code below makes a query in the database and displays what was obtained.
<?php
$serverName = "DESKTOP-B8EB4SG\SQLEXPRESS";
$connectionInfo = array( "Database"=>"contas", "UID"=>"sa", "PWD"=>"123456" );
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
//$sql = "INSERT INTO usuarios (login, senha) VALUES (?, ?)";
$seleciona = "SELECT Login FROM pessoas WHERE UID=3";
// Executa a consulta
$stmt = sqlsrv_query($conn, $seleciona);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
if ($stmt == "renato")
echo "Bem-vindo";
// Exibe o resultado
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
echo $row['Login'].'<br>';
}
?>
I would like when the login name obtained was re-birth, he displayed Welcome. After all, why doesn’t the welcome appear? You might need some kind of string/char conversion?
NOTE: I know there must be infinite explanations about this, but I don’t know exactly what to research.
$stmt
is a Resource and will never equal a string likerenato
. Don’t go in that if inline.– rray
What can I do?
– Luiz Nascimento
Can do
echo 'bem vindo '. $row['Login'].'<br>';
– rray
Only the welcome appeared
– Luiz Nascimento