TW
2010-07-25 23:50:37 UTC
I don't know if this is a SQL Anywhere problem or a PHP problem, but
it only seems to happen with SQL Anywhere so I'm suspicious :-)
I'm using SQL Anywhere 11.0.1.2452 and PHP 5.3.1.
There seems to be something funny about the resource returned by
sasql_stmt_result_metadata. When I run the script below, I get the
output shown.
You can see that just after the value for $_rs in DBResult is set, the
print statement shows it to be a SQLAnywhere result resource. When
it is tested a few statements later, it is still a resource, but the
type is now unknown, causing the subsequent call to sasql_fetch_array
to fail.
If I exchange line 8 for line 9 so that the 'query' call is used
instead of 'pquery' in the script below (i.e., it uses sasql_query
instead of sasql_prepare etc.), it works fine.
I'd appreciate any help,
Thanks,
Terry
OUTPUT:
SETRESOURCETYPE:Resource id #4SQLAnywhere result
test1RESOURCETYPE:Resource id #4SQLAnywhere result
test2RESOURCETYPE:Resource id #4Unknown
Warning: sasql_fetch_array(): 4 is not a valid SQLAnywhere result
resource in C:\Users\Terry Wilkinson\Documents\EclipseWorkspaces\PHP\NQ
\test.php on line 11
SCRIPT:
<?php
$db = new DBConnection();
$db->connect();
$sql = "select * from nqTests where eID = 3";
//$rsx = $db->query( $sql ); //WORKS IF I USE THIS ONE
$rsx = $db->pquery( $sql ); //FAILS IF I USE THIS ONE
print "test2RESOURCETYPE:$rsx->_rs".get_resource_type($rsx-
class DBConnection {
private $_cn;
public function connect() {
$this->_cn =
sasql_connect( "ENG=swcore_service;DBN=swCore;UID=DBA;PWD=sql" );
}
public function query( $sql ) {
$rs = sasql_query( $this->_cn, $sql, SASQL_USE_RESULT );
$newrs = new DBResult( $rs );
print "test1RESOURCETYPE:$newrs->_rs".get_resource_type($newrs-
}
public function pquery( $sql ) {
$stmt = sasql_prepare( $this->_cn, $sql );
if( $stmt ) {
$ok = sasql_stmt_execute( $stmt );
if( $ok ) {
$rs = sasql_stmt_result_metadata( $stmt );
$newrs = new DBResult( $rs );
print "test1RESOURCETYPE:$newrs->_rs".get_resource_type($newrs-
}
}
throw new Exception( $this->errorMessage());
}
}
class DBResult {
public $_rs;
public function DBResult( $rs ) {
$this->_rs = $rs;
print "SETRESOURCETYPE:$this->_rs".get_resource_type($this-
}
?>
it only seems to happen with SQL Anywhere so I'm suspicious :-)
I'm using SQL Anywhere 11.0.1.2452 and PHP 5.3.1.
There seems to be something funny about the resource returned by
sasql_stmt_result_metadata. When I run the script below, I get the
output shown.
You can see that just after the value for $_rs in DBResult is set, the
print statement shows it to be a SQLAnywhere result resource. When
it is tested a few statements later, it is still a resource, but the
type is now unknown, causing the subsequent call to sasql_fetch_array
to fail.
If I exchange line 8 for line 9 so that the 'query' call is used
instead of 'pquery' in the script below (i.e., it uses sasql_query
instead of sasql_prepare etc.), it works fine.
I'd appreciate any help,
Thanks,
Terry
OUTPUT:
SETRESOURCETYPE:Resource id #4SQLAnywhere result
test1RESOURCETYPE:Resource id #4SQLAnywhere result
test2RESOURCETYPE:Resource id #4Unknown
Warning: sasql_fetch_array(): 4 is not a valid SQLAnywhere result
resource in C:\Users\Terry Wilkinson\Documents\EclipseWorkspaces\PHP\NQ
\test.php on line 11
SCRIPT:
<?php
$db = new DBConnection();
$db->connect();
$sql = "select * from nqTests where eID = 3";
//$rsx = $db->query( $sql ); //WORKS IF I USE THIS ONE
$rsx = $db->pquery( $sql ); //FAILS IF I USE THIS ONE
print "test2RESOURCETYPE:$rsx->_rs".get_resource_type($rsx-
_rs)."<br>";
$row = sasql_fetch_array( $rsx->_rs );class DBConnection {
private $_cn;
public function connect() {
$this->_cn =
sasql_connect( "ENG=swcore_service;DBN=swCore;UID=DBA;PWD=sql" );
}
public function query( $sql ) {
$rs = sasql_query( $this->_cn, $sql, SASQL_USE_RESULT );
$newrs = new DBResult( $rs );
print "test1RESOURCETYPE:$newrs->_rs".get_resource_type($newrs-
_rs)."<br>";
return $newrs;}
public function pquery( $sql ) {
$stmt = sasql_prepare( $this->_cn, $sql );
if( $stmt ) {
$ok = sasql_stmt_execute( $stmt );
if( $ok ) {
$rs = sasql_stmt_result_metadata( $stmt );
$newrs = new DBResult( $rs );
print "test1RESOURCETYPE:$newrs->_rs".get_resource_type($newrs-
_rs)."<br>";
return $newrs;}
}
throw new Exception( $this->errorMessage());
}
}
class DBResult {
public $_rs;
public function DBResult( $rs ) {
$this->_rs = $rs;
print "SETRESOURCETYPE:$this->_rs".get_resource_type($this-
_rs)."<br>";
}}
?>
--
You received this message because you are subscribed to the Google Groups "SQL Anywhere Web Development" group.
To post to this group, send email to sql-anywhere-web-***@googlegroups.com.
To unsubscribe from this group, send email to sql-anywhere-web-development+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sql-anywhere-web-development?hl=en.
You received this message because you are subscribed to the Google Groups "SQL Anywhere Web Development" group.
To post to this group, send email to sql-anywhere-web-***@googlegroups.com.
To unsubscribe from this group, send email to sql-anywhere-web-development+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sql-anywhere-web-development?hl=en.