⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ifx.ec

📁 php-4.4.7学习linux时下载的源代码
💻 EC
📖 第 1 页 / 共 5 页
字号:
	return SUCCESS;}PHP_MSHUTDOWN_FUNCTION(ifx) {	UNREGISTER_INI_ENTRIES();	return SUCCESS;}PHP_RINIT_FUNCTION(ifx) {	IFXG(default_link) = -1;	IFXG(num_links) = IFXG(num_persistent);	return SUCCESS;}PHP_MINFO_FUNCTION(ifx){	char buf[32];	php_info_print_table_start();	php_info_print_table_header(2, "Informix support", "enabled");	sprintf(buf, "%ld", IFXG(num_persistent));	php_info_print_table_row(2, "Active Persistent links", buf);	sprintf(buf, "%ld", IFXG(num_links)); 	php_info_print_table_row(2, "Active links", buf);	sprintf(buf, "%02.2f", (double)(IFX_VERSION/100.0)); 	php_info_print_table_row(2, "ESQL/C Version", buf);	php_info_print_table_end();	DISPLAY_INI_ENTRIES();}static void php_ifx_set_default_link(int id TSRMLS_DC) {	if (IFXG(default_link) != -1) {		zend_list_delete(IFXG(default_link));	}	IFXG(default_link) = id;	zend_list_addref(id);}/* ----------------------------------------------------------------------** int ifx_(p)connect(string database, string userid, string password)**** connects to $database (db@server syntax) using $userid and $password**** returns a connection id on success or FALSE one error  ** ----------------------------------------------------------------------*/static void php_ifx_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent){	char *hashed_details;	int hashed_details_length;EXEC SQL BEGIN DECLARE SECTION;	char *user,*passwd,*host;	char *ifx;EXEC SQL END DECLARE SECTION;	if (PG(sql_safe_mode)) {		if (ZEND_NUM_ARGS() > 0) {			php_error_docref(NULL TSRMLS_CC, E_NOTICE, "SQL safe mode in effect - ignoring host/user/password information");		}		host = passwd = NULL;		user = php_get_current_user();		hashed_details_length = strlen(user) + 3 + 3;		hashed_details = (char *) emalloc(hashed_details_length + 1);		sprintf(hashed_details, "ifx__%s_", user);	} else {		int host_len = 0, user_len = 0, passwd_len = 0;		host = user = passwd = NULL;		/* set default values if any are available */		if (IFXG(default_host)) {			host = IFXG(default_host);			host_len = strlen(host);		}		if (IFXG(default_user)) {			user = IFXG(default_user);			user_len = strlen(IFXG(default_user));		}		if (IFXG(default_password)) {			passwd = IFXG(default_password);			passwd_len = strlen(IFXG(default_password));		}		if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sss", &host, &host_len, &user, &user_len, &passwd, &passwd_len) == FAILURE) {			return;		}		hashed_details_length = sizeof("ifx___") - 1 + host_len + user_len + passwd_len;		hashed_details = (char *) emalloc(hashed_details_length + 1);		sprintf(hashed_details, "ifx_%s_%s_%s", SAFE_STRING(host), SAFE_STRING(user), SAFE_STRING(passwd));	}	IFXG(sv_sqlcode) = 0;	if (!IFXG(allow_persistent)) {		persistent = 0;	}	if (persistent) {		list_entry *le;		/* try to find if we already have this link in our persistent list */		if (zend_hash_find(&EG(persistent_list), hashed_details, hashed_details_length + 1, (void **) &le) == FAILURE) {  /* we don't */			list_entry new_le;			if (IFXG(max_links) != -1 && IFXG(num_links) >= IFXG(max_links)) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%d)", IFXG(num_links));				efree(hashed_details);				RETURN_FALSE;			}			if (IFXG(max_persistent) != -1 && IFXG(num_persistent) >= IFXG(max_persistent)) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open persistent links (%d)", IFXG(num_persistent));				efree(hashed_details);				RETURN_FALSE;			}			/* create the link */			ifx = (char *) malloc(sizeof(IFX));			IFXG(connectionid)++;			sprintf(ifx, "%s%x_%x", SAFE_STRING(user), IFX_THRD_ID,IFXG(connectionid));						EXEC SQL CONNECT TO :host AS :ifx USER :user USING :passwd WITH CONCURRENT TRANSACTION;  				if (ifx_check() == IFX_ERROR) {				char *ifx_err = ifx_error(ifx);				IFXG(sv_sqlcode) = SQLCODE;				php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ifx_err);				efree(ifx_err);				free(ifx);				efree(hashed_details);				RETURN_FALSE;			}			/* hash it up */			new_le.type = le_plink;			new_le.ptr = ifx;			if (zend_hash_update(&EG(persistent_list), hashed_details, hashed_details_length + 1, (void *) &new_le, sizeof(list_entry), NULL) == FAILURE) {				free(ifx);				efree(hashed_details);				RETURN_FALSE;			}			IFXG(num_persistent)++;			IFXG(num_links)++;		} else {  /* we do */			if (le->type != le_plink) {				RETURN_FALSE;			}			/* ensure that the link did not die */			ifx = le->ptr;			EXEC SQL SET CONNECTION :ifx;			if (ifx_check() == IFX_ERROR) { /* the link died */				ifx = le->ptr;	/* reconnect silently */				EXEC SQL CONNECT TO :host AS :ifx USER :user USING :passwd WITH CONCURRENT TRANSACTION;  								if (ifx_check() == IFX_ERROR) {					char *ifx_err = ifx_error(ifx);					IFXG(sv_sqlcode) = SQLCODE;					php_error_docref(NULL TSRMLS_CC, E_WARNING, "Link to server lost, unable to reconnect (%s)", ifx_err);					zend_hash_del(&EG(persistent_list), hashed_details, hashed_details_length + 1);					efree(ifx_err);					efree(hashed_details);					RETURN_FALSE;				}			}			ifx = le->ptr;		}		ZEND_REGISTER_RESOURCE(return_value, ifx, le_plink);	} else { /* non persistent */		list_entry *index_ptr,new_index_ptr;		/* first we check the hash for the hashed_details key.  if it exists,		 * it should point us to the right offset where the actual ifx link sits.		 * if it doesn't, open a new ifx link, add it to the resource list,		 * and add a pointer to it with hashed_details as the key.		 */		if (zend_hash_find(&EG(regular_list), hashed_details, hashed_details_length + 1, (void **) &index_ptr) == SUCCESS)		{			int type,link;			void *ptr;			if (index_ptr->type != le_index_ptr) {				RETURN_FALSE;			}			link = (int) index_ptr->ptr;			ptr = zend_list_find(link, &type);   /* check if the link is still there */			if (ptr && (type == le_link || type == le_plink)) {				/* ensure that the link is not closed */				ifx = ptr;				EXEC SQL SET CONNECTION :ifx;				if (ifx_check() == IFX_ERROR) {					/* the link is closed */					ifx = ptr;	/* reconnect silently */					EXEC SQL CONNECT TO :host AS :ifx USER :user USING :passwd WITH CONCURRENT TRANSACTION;  					if (ifx_check() == IFX_ERROR) {						char *ifx_err = ifx_error(ifx);						IFXG(sv_sqlcode) = SQLCODE;						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to connect (%s)", ifx_err);						zend_hash_del(&EG(regular_list), hashed_details, hashed_details_length + 1);						efree(hashed_details);						efree(ifx_err);						RETURN_FALSE;					}				}				zend_list_addref(link);				return_value->value.lval = link;				php_ifx_set_default_link(link TSRMLS_CC);				return_value->type = IS_RESOURCE;				efree(hashed_details);				return;			} else {				zend_hash_del(&EG(regular_list), hashed_details, hashed_details_length + 1);			}		}		if (IFXG(max_links) != -1 && IFXG(num_links) >= IFXG(max_links)) {			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too many open links (%d)", IFXG(num_links));			efree(hashed_details);			RETURN_FALSE;		}		ifx = (char *) emalloc(sizeof(IFX));		IFXG(connectionid)++;		sprintf(ifx, "connec%x_%x", IFX_THRD_ID, IFXG(connectionid));				EXEC SQL CONNECT TO :host AS :ifx USER :user USING :passwd WITH CONCURRENT TRANSACTION;		if (ifx_check() == IFX_ERROR) {			char *ifx_err = ifx_error(ifx);			IFXG(sv_sqlcode) = SQLCODE;			php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ifx_err);			efree(ifx_err);			efree(hashed_details);			efree(ifx);			RETURN_FALSE;		}		/* add it to the list */		ZEND_REGISTER_RESOURCE(return_value, ifx, le_link);		/* add it to the hash */		new_index_ptr.ptr = (void *) return_value->value.lval;		new_index_ptr.type = le_index_ptr;		if (zend_hash_update(&EG(regular_list), hashed_details, hashed_details_length + 1, (void *) &new_index_ptr, sizeof(list_entry), NULL) == FAILURE) {			efree(hashed_details);			RETURN_FALSE;		}		IFXG(num_links)++;	}	efree(hashed_details);	php_ifx_set_default_link(return_value->value.lval TSRMLS_CC);}/* {{{ proto resource ifx_connect([string database [, string userid [, string password]]])   Connects to database using userid/password, returns connection id */PHP_FUNCTION(ifx_connect){	php_ifx_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,0);}/* }}} *//* {{{ proto resource ifx_pconnect([string database [, string userid [, string password]]])   Connects to database using userid/password, returns connection id */PHP_FUNCTION(ifx_pconnect){	php_ifx_do_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU,1);}/* }}} *//* ----------------------------------------------------------------------** int ifx_close(int connid)**** closes connection connid ** always returns TRUE** ----------------------------------------------------------------------*//* {{{ proto bool ifx_close([resource connid])   Close informix connection */PHP_FUNCTION(ifx_close){	zval **ifx_link = NULL;	int id;EXEC SQL BEGIN DECLARE SECTION;	char *ifx;EXEC SQL END DECLARE SECTION;	switch (ZEND_NUM_ARGS()) {		case 0:			id = IFXG(default_link);			break;		case 1:			if (zend_get_parameters_ex(1, &ifx_link) == FAILURE) {				RETURN_FALSE;			}			id=-1;			break;		default:			WRONG_PARAM_COUNT;			break;	}	IFXG(sv_sqlcode) = 0;	ZEND_FETCH_RESOURCE2(ifx, char *, ifx_link, id, "Informix link", le_link, le_plink);	if (id == -1) { /* explicit resource number */		zend_list_delete(Z_RESVAL_PP(ifx_link));	}		if (id != -1 || (ifx_link && Z_RESVAL_PP(ifx_link) == IFXG(default_link))) {		zend_list_delete(IFXG(default_link));		IFXG(default_link) = -1;	}	RETURN_TRUE;}/* }}} *//* ----------------------------------------------------------------------** int ifx_query(string query, int connid **               [, int cursortype] [, array blobidarray])** cursortype and blobidarray are optional** ** executes query query on connection connid** for select queries a cursor is declared and opened** non-select queries are "execute immediate"** select queries accept an optional cursortype param: ** IFX_SCROLL, IFX_HOLD (or'ed mask)** non-select queries accept an optional "blobarryid" parameter** blobsupport: mark the blob-column(s) with ? in the insert/update query **   and add a blob-id-array-functionparameter** select queries return "blob-ids" for blob columns **   except if text/byteasvarchar is set** example: ifx_query("insert into catalog (stock_num, manu_code, **           cat_descr,cat_picture) values(1,'HRO',?,?)",$cid,$bidarray);** ** returns a "result id" on success or FALSE on error** also sets "affected_rows for retrieval by ifx_affected_rows()** ----------------------------------------------------------------------*//* {{{ proto resource ifx_query(string query, resource connid [, int cursortype] [, array idarray])   Perform a query on a given connection */PHP_FUNCTION(ifx_query){	zval **query, **ifx_link, **cursortype, **dummy;	int id=-1;	IFX_RES *Ifx_Result;EXEC SQL BEGIN DECLARE SECTION;	char *ifx;                /* connection ID     */	char cursorid[32];        /* query cursor id   */	char statemid[32];        /* statement id      */	char descrpid[32];        /* descriptor id     */	char i_descrpid[32];      /* input descriptor binding */	char *statement;          /* query text        */	int  fieldcount;          /* field count       */	int  i;                   /* field index       */	short fieldtype;	loc_t *locator=NULL;	int loc_t_type=CLOCATORTYPE;  /* WORKAROUND:TYPE=CLOCATORTYPE doesn't work,  */	int sqlchar_type=SQLCHAR;     /* don't ask me, why. */	char *char_tmp;	long len;	int indicator;	int desc_count;$ifdef HAVE_IFX_IUS;	fixed binary 'blob' ifx_lo_t *slocator;$endif;EXEC SQL END DECLARE SECTION;	int  locind;	int  ctype;	int  affected_rows;	long sqlerrd[6];	int  e;	int  query_type;	int  cursoryproc;	int  argc=ZEND_NUM_ARGS();	long ifx_type;	int num_params;	if (argc < 2 || zend_get_parameters_ex(argc, &query, &ifx_link, &dummy, &dummy) == FAILURE) {		WRONG_PARAM_COUNT;	}	ZEND_FETCH_RESOURCE2(ifx, char *, ifx_link, id, "Informix link", le_link, le_plink);	IFXG(sv_sqlcode) = 0;	affected_rows = -1;		/* invalid */	convert_to_string_ex(query);	statement = Z_STRVAL_PP(query);	IFXG(cursorid)++;	sprintf(statemid, "statem%x_%x", IFX_THRD_ID, IFXG(cursorid));	sprintf(cursorid, "cursor%x_%x", IFX_THRD_ID, IFXG(cursorid));	sprintf(descrpid, "descrp%x_%x", IFX_THRD_ID, IFXG(cursorid));	sprintf(i_descrpid, "i_descrp%x_%x", IFX_THRD_ID,IFXG(cursorid));	EXEC SQL set connection :ifx;	PHP_IFX_CHECK_CONNECTION(ifx);	EXEC SQL PREPARE :statemid FROM :statement;	if (ifx_check() < 0) {		char *ifx_err = ifx_error(ifx);		IFXG(sv_sqlcode) = SQLCODE;		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Prepare fails (%s)", ifx_err);		efree(ifx_err);		RETURN_FALSE;	}	affected_rows = sqlca.sqlerrd[0];	/* save estimated affected rows */	for (e = 0; e < 6; e++) sqlerrd[e] = sqlca.sqlerrd[e];   	num_params = php_intifx_preparse(statement TSRMLS_CC);	Ifx_Result = (IFX_RES *) emalloc(sizeof(IFX_RES));	if (Ifx_Result == NULL) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -