bluewalrus
06-18-2009, 11:08 PM
Don't know if this should be in here or in the sql forum but this is where I've put it... I'm trying to get values from a mircosoft sql server, I can successfully retrieve 6 of the 9 using sqlsrv_get_field. However the last three just come up blank.
I've tried using this but it still doesn't work. http://msdn.microsoft.com/en-us/library/cc296207(SQL.90).aspx
The two items that won't show up are of type text and datetime which I think is the problem I attempt to use the stream solution at the bottom of that link but it Did not produce any code with it.
This is my code thus far. Thanks for any help you can offer.
<?php
/*Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
$serverName = "SERVER";
$connectionInfo = array("Database" => "name");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Set up and execute the query. Note that both ReviewerName and
Comments are of the SQL Server nvarchar type. */
$tsql = "Select Top 5 dte, id, name, video, song, d, thumb From table where dte <= GetDate() order by dte Desc";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in statement preparation/execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Make the first row of the result set available for reading. */
if( sqlsrv_fetch( $stmt ) === false )
{
echo "Error in retrieving row.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Note: Fields must be accessed in order.
Get the first field of the row. Note that no return type is
specified. Data will be returned as a string, the default for
a field of type nvarchar.*/
$dte1 = sqlsrv_get_field( $stmt, 0); /*DOESN'T WORK */
$tle1 = sqlsrv_get_field( $stmt, 1);
$aff1 = sqlsrv_get_field( $stmt, 2);
$aut1 = sqlsrv_get_field( $stmt, 3); /*DOESN'T WORK */
$strc1 = sqlsrv_get_field( $stmt, 4); /*DOESN'T WORK */
$vID1 = sqlsrv_get_field( $stmt, 5);
$id1 = sqlsrv_get_field( $stmt, 6);
echo "id: $tle1 <br />";
echo "tmb: $id1 <br />";
echo "title: $aff1 <br />";
echo "aut: $aut1 <br />"; /*displays aut:*/
echo "aff: $strc1 <br />"; /*displays aff: */
echo "vid: $vID1 <br />";
echo "date: $dte1 <br />"; /*displays nothing.... */
/* Free the statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
I've tried using this but it still doesn't work. http://msdn.microsoft.com/en-us/library/cc296207(SQL.90).aspx
The two items that won't show up are of type text and datetime which I think is the problem I attempt to use the stream solution at the bottom of that link but it Did not produce any code with it.
This is my code thus far. Thanks for any help you can offer.
<?php
/*Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
$serverName = "SERVER";
$connectionInfo = array("Database" => "name");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Set up and execute the query. Note that both ReviewerName and
Comments are of the SQL Server nvarchar type. */
$tsql = "Select Top 5 dte, id, name, video, song, d, thumb From table where dte <= GetDate() order by dte Desc";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in statement preparation/execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Make the first row of the result set available for reading. */
if( sqlsrv_fetch( $stmt ) === false )
{
echo "Error in retrieving row.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Note: Fields must be accessed in order.
Get the first field of the row. Note that no return type is
specified. Data will be returned as a string, the default for
a field of type nvarchar.*/
$dte1 = sqlsrv_get_field( $stmt, 0); /*DOESN'T WORK */
$tle1 = sqlsrv_get_field( $stmt, 1);
$aff1 = sqlsrv_get_field( $stmt, 2);
$aut1 = sqlsrv_get_field( $stmt, 3); /*DOESN'T WORK */
$strc1 = sqlsrv_get_field( $stmt, 4); /*DOESN'T WORK */
$vID1 = sqlsrv_get_field( $stmt, 5);
$id1 = sqlsrv_get_field( $stmt, 6);
echo "id: $tle1 <br />";
echo "tmb: $id1 <br />";
echo "title: $aff1 <br />";
echo "aut: $aut1 <br />"; /*displays aut:*/
echo "aff: $strc1 <br />"; /*displays aff: */
echo "vid: $vID1 <br />";
echo "date: $dte1 <br />"; /*displays nothing.... */
/* Free the statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>