$sql = "SELECT Ptittle FROM dbo.Pcontent WHERE Pname='$Fname'"; $result = sqlsrv_query ($conn,$sql); echo $result; 

Why without:

 WHERE Pname='$Fname' 

returns the value of Resursid#6 , and if I add a variable returns nothing?

  • $ result is not the data received, but a handle to the result of the query; further, it is necessary to execute the fetch functions in order to extract data by the handle. - Jean-Claude
  • examples on the docks php.net/manual/ru/function.sqlsrv-fetch-array.php - Jean-Claude
  • Nah does not work: C - qaz qaz

1 answer 1

  1. Instead of echo $result; use var_dump($result); and you will see that you actually returned to the answer (for example, false );
  2. Before asking questions, review the Microsoft SQL Server DBMS Driver Documentation for PHP and see examples of using functions:

     <?php $serverName = "serverName\sqlexpress"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password" ); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "INSERT INTO Table_1 (id, data) VALUES (?, ?)"; $params = array(1, "some data"); $stmt = sqlsrv_query( $conn, $sql, $params); if( $stmt === false ) { die( print_r( sqlsrv_errors(), true)); } 
  • insert is not significant) select is a more illustrative example php.net/manual/ru/function.sqlsrv-fetch-array.php - Jean-Claude
  • @ Jean-Claude, I look at the author's questions and I think that no matter what examples to write in the answers :) - Visman
  • yes)) but what about the spirit of the community?)))) - Jean-Claude
  • read man, made, but earned! $ sql = "SELECT Ptittle FROM dbo.Pcontent WHERE Pname = $ Fname"; $ stmt = sqlsrv_query ($ conn, $ sql); if ($ stmt === false) {die (print_r (sqlsrv_errors (), true)); $ row = sqlsrv_fetch_array ($ stmt); echo $ row ['Ptittle']; - qaz qaz
  • even though I tell him that I need this particular array element, it displays everything to me completely: Array ([0] => Array ([0] => 42000 [SQLSTATE] => 42000 [1] => 4104 [code] = > 4104 [2] => [Microsoft] [ODBC Driver 13 for SQL Server] [SQL Server] "mopr.php". [Message] => [Microsoft] [ODBC Driver 13 for SQL Server] [SQL Server] "mopr .php ".)) and the value that lies in the cell is not - qaz qaz