Introduction + Using another extension's resources
| From: | weedguy | Date: | Sat, 17 Jan 2009 09:58:54 +0000 |
| Subject: | Introduction + Using another extension's resources | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-6057@lists.php.net to get a copy of this message | ||
Hello everyone,
My name is Raj, and I'm a college student pursuing a Bachelor's Degree in
Software Engineering, with programming experience in PHP, Java, and to an
extent C/C++. I began learning how to build a PHP extension about a week
ago, and am in the midst of building my first PHP extension.
I've encountered numerous problems, most of which I've managed to resolve
with the relevant tutorials online. There is one problem though that I'm
unable to resolve. I'm attempting to use another extension's resources, the
PHP MySQL extension to be exact. The following is my code:
ZEND_FUNCTION(test_func)
{
int argc = ZEND_NUM_ARGS();
if (1 != argc)
WRONG_PARAM_COUNT;
zval *mysql_res = NULL;
php_mysql_conn *mysql = NULL;
int res_type = -1;
if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc
TSRMLS_CC, "r", &mysql_res))
RETURN_NULL();
mysql = (php_mysql_conn *) zend_list_find(Z_RESVAL_P(mybs_res),
&res_type);
mysql_close(&mysql->conn);
}
Now, everything works fine until I pass mysql->conn to mysql_close. At this
point, I get a seg fault whenever I try to call the above function in my PHP
script. The argument I pass to this function is the resource returned by
calling the php mysql_connect() function. If I get a MySQL reference via
mysql_real_connect() and pass it to mysql_close() directly within the
test_func definition, everything works fine. I've considered using
ZEND_FETCH_RESOURCE and ZEND_FETCH_RESOURCE2, but both of them require link
descriptors for the MySQL resource, which I don't have access to.
I've also checked the forums, and there was a mention of how to access
another extension's resources, either statically or by using the
ZEND_MOD_REQUIRED macro. I'm not to keen on static linking, and I'm not
entirely sure on what to do exactly after specifying
ZEND_MOD_REQUIRED("mysql") as a dependency (I checked the pdo_sqlite
extension source, not much help from there).
Some light on this issue would be great :)
Thanks in advance.
Regards,
Raj
--
View this message in context: http://www.nabble.com/Introduction-%2B-Using-another-extension%27s-resources-tp21514767p21514767.html
Sent from the Pecl - Dev mailing list archive at Nabble.com.