Comments (3)
On 2014-01-09 17:24:53 UTC, robertjohnson commented:
It's a bug, it only works properly when called once and once-only per result.
Internally sqlsrv_has_rows simply calls sqlsrv_fetch, so you can do the same.
If you open a scrollable cursor, you can rewind it. If it's a forward cursor, just remember that you fetched the first row.
from msphpsql.
The first problem no longer exists but I'm able to reproduce the second problem with the following repro script (happens in both Windows and Linux):
// this table has three rows
$stmt = sqlsrv_query( $conn, "select name from fruit" );
if (! $stmt) {
echo "Query failed\n";
die (print_r(sqlsrv_errors(), true));
}
// if we skip the next three calls it's fine
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
// but after calling sqlsrv_has_rows() three times, the following
// if statement will return false, so no data is fetched
if (sqlsrv_has_rows($stmt)) {
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))
{
var_dump($row);
}
}
Expected Output:
Has Rows? Yes!
Has Rows? Yes!
Has Rows? Yes!
array(1) {
[0]=>
string(5) "apple"
}
array(1) {
[0]=>
string(6) "banana"
}
array(1) {
[0]=>
string(9) "blueberry"
}
Actual Output:
Has Rows? Yes!
Has Rows? Yes!
Has Rows? Yes!
from msphpsql.
Fixed by #256
from msphpsql.
Related Issues (20)
- Setting PDO::ATTR_STRINGIFY_FETCHES throws exception HOT 14
- Release beta with support for PHP 8.3 RC 1 HOT 20
- TrustServerCertificate no longer working in v5.11.1 HOT 9
- SQLSTATE[HY000]: [Microsoft][ODBC Driver 18 for SQL Server]Unicode conversion failed HOT 14
- CentOS9 SQL Server 2014 connect failed. Microsoft ODBC Driver 18 for SQL Server : TCP Provider: Error code 0x2746. HOT 6
- Cakephp2 Application takes longer time to fetch data from sql server database resulting php memory error HOT 3
- Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server HOT 1
- Memory leak in Microsoft ODBC Driver 17.10.5 for SQL Server HOT 4
- HY104 Invalid precision value when reusing prepared statement HOT 4
- SQLSTATE[01002] Adaptive Server connection failed (xxx.xx.xx.xxx) HOT 1
- Issue connecting to SQL server from Openshift HOT 1
- Unable to build version 5.12.0beta1 on Windows HOT 2
- New attribute for sql bigint and decimal/numeric types to php int and float types HOT 1
- Performance problem when using params on select query HOT 2
- Error on both ARM64 and AMD64 docker build HOT 1
- apt fails to install from pmc-geofence.trafficmanager.net: 403 Forbidden HOT 10
- Error requesting access token while Azure webapps (php) connect to Azure SQL server by UMI HOT 4
- Windows DLL available to download HOT 1
- unable to install in ubuntu 22.04 container HOT 1
- SQL server connection HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msphpsql.