Page 1 of 1

ODBC Call & connection status

Posted: Mon May 12, 2003 6:49 am
by mlr
Hi,

I have the following situation. At our company we have our own database and have written our own odbc driver. Using php we can access our database without any problem.

What now occurs is the user executes a query which takes a long time to return (difficult query with subselects etc.). My problem is when the query is executing I would like to check from the quering process the connection status of thje client. So is it still alive , or is the connection aborted. Anyone has any ideas how to accomplish this ?

Thanks in advance,

Marco Laponder
mlr AT interchain DOT nl

Posted: Mon May 12, 2003 7:38 am
by volka
http://www.php.net/manual/en/features.c ... ndling.php describes what php offers in this matter

Posted: Mon May 12, 2003 7:42 am
by mlr
I am famliar with the link you gave me. The problem is during the expensive ODBC call I cannot execute the PHP script. So I would like to call from my own odbc driver the function connection_status() or check if the client is alive in an other way. As far as I can see now I can only check when I returned from the ODBC call but that means an expensive ODBC call is processed even if the user canceled the request.

Kind regards,
Marco Laponder
mlr@interchain.nl

Posted: Mon May 12, 2003 8:09 am
by volka
did you write your own odbc-driver or an odbc-like extension for php to access the database?
The driver probably cannot access the php engine process, how should it obtain the information? An extension can.

Posted: Mon May 12, 2003 8:17 am
by mlr
It is an odbc driver and not an extension. If I wrote a extension instead of a driver could I check the connection status in that option ? (I have no experience on creating extensions). When I create an extension am I defining my own php functions ?

Kind regards,
Marco Laponder
mlr AT interchain DOT nl

Posted: Mon May 12, 2003 8:59 am
by volka
right, take a look at http://www.php.net/manual/en/zend.php
php_odbc itself is an extension (for win32 it's a.. eh... built-in extension ;) ) so have a read of this module's source, too.

Posted: Tue May 13, 2003 3:43 am
by mlr
Just a couple of another questions (I am a newbi at extensions so please be patient).

How could I check from my own extension (say my_checkstatus_odbc_fetch() ) the connection status ? Could I call any php function for that ? Any idea when the connection status is updated ?

TIA
Marco Laponder
mlr AT interchain DOT nl

Posted: Tue May 13, 2003 5:26 am
by volka
Yes, you can call any function, Chapter 38. Calling User Functions describes it

But getting the connection status might be easier. Take a look at the implementions of connection_aborted() and connection_status()

Code: Select all

/* {{{ proto int connection_aborted(void)
   Returns true if client disconnected */
PHP_FUNCTION(connection_aborted)
{
	RETURN_LONG(PG(connection_status) & PHP_CONNECTION_ABORTED);
}
/* }}} */

/* {{{ proto int connection_status(void)
   Returns the connection status bitfield */
PHP_FUNCTION(connection_status)
{
	RETURN_LONG(PG(connection_status));
}
/* }}} */
PG(v) is defined as

Code: Select all

# define PG(v) TSRMG(core_globals_id, php_core_globals *, v)
so it's simply fetching an entry from a global table.
But I can't tell you when this is updated, I not that familiar with the php-source in general and extensions in particular ;)

Posted: Tue May 13, 2003 5:41 am
by mlr
Oke, thanks for your info. I will try to get it to work...I lett you know my progress

Thanks again,

Marco Laponder