it work thisway, Ihope
you have taken
adoubtsomeonewho has thesame
doubts
that
had
<?php
/* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
$serverName = "(local)";
$connectionInfo = array("UID" => 'systemapp', "PWD" => 'senha', "Database"=>"TSQLFundamentals2008");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Define the query. */
$tsql = "SELECT firstname,
lastname
FROM HR.Employees";
/* Execute the query. */
$stmt = sqlsrv_query( $conn, $tsql);
if ( $stmt )
{
/* Iterate through the result set printing a row of data upon each
iteration.*/
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_BOTH))
{
echo "Firstname: ".$row[0]."\n";
echo "Lastname: ".$row[1]."\n";
}
3 Posts
PHP + DRIVE SQL FOR PHP + IIS 7.5 error retrieving data from the table
Apr 14, 2011 01:06 PM|scia_2005|LINK
<?php
$serverName = "(local)";
$connectionInfo = array("UID" => 'systemapp', "PWD" => 'senha', "Database"=>"TSQLFundamentals2008");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
/* Define the query. */
$tsql = "SELECT * FROM HR.Employees";
/* Execute the query. */
$stmt = sqlsrv_query( $conn, $tsql);
if ( $stmt === false )
{
echo "Error in statement execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Test if query exist rom. *
if ($stmt !== NULL) {
$rows = sqlsrv_has_rows( $stmt );
if ($rows === false)
echo "\nno rows\n";
}
$result = sqlsrv_fetch_array($stmt);
while( !is_null($result));
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
Because the data are not coming back?
when I'm selecting data in database and retrieving it returns all the information
screen sql select:
empid lastname firstname title titleofcourtesy birthdate address city country phone
----------- -------------------- ---------- ------------------------------ ------------------------- ----------------------- ------------------------------------------------------------ --------------- --------------- ------------------------
1 Davis Sara CEO Ms. 1958-12-08 00:00:00.000 7890 - 20th Ave. E., Apt. 2A Seattle USA (206) 555-0101
2 Funk Don Vice President, Sales Dr. 1962-02-19 00:00:00.000 9012 W. Capital Way Tacoma USA (206) 555-0100
3 Lew Judy Sales Manager Ms. 1973-08-30 00:00:00.000 2345 Moss Bay Blvd. Kirkland USA (206) 555-0103
4 Peled Yael Sales Representative Mrs. 1947-09-19 00:00:00.000 5678 Old Redmond Rd. Redmond USA (206) 555-0104
5 Buck Sven Sales Manager Mr. 1965-03-04 00:00:00.000 8901 Garrett Hill London UK (71) 234-5678
6 Suurs Paul Sales Representative Mr. 1973-07-02 00:00:00.000 3456 Coventry House, Miner Rd. London UK (71) 345-6789
7 King Russell Sales Representative Mr. 1970-05-29 00:00:00.000 6789 Edgeham Hollow, Winchester Way London UK (71) 123-4567
8 Cameron Maria Sales Representative Ms. 1968-01-09 00:00:00.000 4567 - 11th Ave. N.E. Seattle USA (206) 555-0102
9 Dolgopyatova Zoya Sales Representative Ms. 1976-01-27 00:00:00.000 1234 Houndstooth Rd. London UK (71) 456-7890
(9 row(s) affected)
I'M USING SQL SERVER 2008 R2 with IIS 7.5 on Windows Server 2008 R2 drive and version 2.0 for PHP SQL latest version.
I downloaded the test database from microsoft and they send AdventureWork I use the command
$ name = sqlsrv_get_field ($ stmt, 0) / / retrieves the name of the guy
echo "$ name";
$ stream = sqlsrv_get_field ($ stmt, 1,
SQLSRV_PHPTYPE_STREAM (SQLSRV_ENC_CHAR)) / / retrieves a sting that I set
while (! feof ($ stream))
{
$ str = fread ($ stream, 10000);
echo $ str;
}
to retrieve information that is the sql command is:
$ tsql = "SELECT reviewerName, Comments
FROM Production.ProductReview
WHERE ProductReviewID = 1 ";
so I want to list all without getting any life as putting WHERE (WHERE ProductReviewID> 1) want it to work initially with the state
$ tsql = "SELECT reviewerName, Comments
FROM Production.ProductReview ";
SOMEBODY HELP ME?
1 Post
Re: PHP + DRIVE SQL FOR PHP + IIS 7.5 error retrieving data from the table
Apr 15, 2011 03:33 AM|Kamas|LINK
Hi,
shoudn't it be
while( !is_null($result)) $result = sqlsrv_fetch_array($stmt); ?
3 Posts
Re: PHP + DRIVE SQL FOR PHP + IIS 7.5 error retrieving data from the table
Apr 18, 2011 07:43 AM|scia_2005|LINK
it work this way, I hope you have taken a doubt someone who has the same doubts that had
<?php
/* Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
$serverName = "(local)";
$connectionInfo = array("UID" => 'systemapp', "PWD" => 'senha', "Database"=>"TSQLFundamentals2008");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Define the query. */
$tsql = "SELECT firstname,
lastname
FROM HR.Employees";
/* Execute the query. */
$stmt = sqlsrv_query( $conn, $tsql);
if ( $stmt )
{
}
else
{
echo "Error in statement execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Iterate through the result set printing a row of data upon each
iteration.*/
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_BOTH))
{
echo "Firstname: ".$row[0]."\n";
echo "Lastname: ".$row[1]."\n";
}
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>