 |
สอบถามเรื่อง ฟังก์ชั่น php ทำงานกับ ฐานข้อมูล SQL Server (SQLSRV) Driver API |
|
 |
|
|
 |
 |
|
ไม่เคยใช้แฮะ ทำไมไม่ใช้ sqlsrv_fetch_array เลยละครับ
|
 |
 |
 |
 |
Date :
2011-05-08 11:57:26 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันมีวิธีที่ ทำการ Select ออกมาแบบเป็น เพจๆ ได้ มีใครพอจะรู้บ้างอะครับ เห็นมีคนบอก ใช้วิธีการ ดีไวท์ หรืออะไรเนี้ย (จำบ่ได้)
|
ประวัติการแก้ไข 2011-05-09 13:05:11 2011-05-09 13:09:45
 |
 |
 |
 |
Date :
2011-05-09 13:03:49 |
By :
thekknd |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับที่มาตอบคำถามผม
|
 |
 |
 |
 |
Date :
2011-05-09 13:04:14 |
By :
thekknd |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
/*Connect to the local server using Windows Authentication and
specify the AdventureWorks database as the database in use. */
$serverName = "(local)";
$connectionInfo = array( "Database"=>"AdventureWorks");
$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 SQL Server type nvarchar. */
$tsql = "SELECT ReviewerName, Comments
FROM Production.ProductReview
WHERE ProductReviewID=1";
$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.*/
$name = sqlsrv_get_field( $stmt, 0);
echo "$name: ";
/*Get the second field of the row as a stream.
Because the default return type for a nvarchar field is a
string, the return type must be specified as a stream. */
$stream = sqlsrv_get_field( $stmt, 1,
SQLSRV_PHPTYPE_STREAM( SQLSRV_ENC_CHAR));
while( !feof( $stream ))
{
$str = fread( $stream, 10000);
echo $str;
}
/* Free the statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
|
 |
 |
 |
 |
Date :
2011-08-04 12:13:42 |
By :
atee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|