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

📄 dbx.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*   +----------------------------------------------------------------------+   | PHP Version 4                                                        |   +----------------------------------------------------------------------+   | Copyright (c) 1997-2007 The PHP Group                                |   +----------------------------------------------------------------------+   | dbx module version 1.0                                               |   +----------------------------------------------------------------------+   | Copyright (c) 2001 Guidance Rotterdam BV                             |   +----------------------------------------------------------------------+   | This source file is subject to version 3.01 of the PHP license,      |   | that is bundled with this package in the file LICENSE, and is        |   | available through the world-wide-web at the following url:           |   | http://www.php.net/license/3_01.txt                                  |   | If you did not receive a copy of the PHP license and are unable to   |   | obtain it through the world-wide-web, please send a note to          |   | license@php.net so we can mail you a copy immediately.               |   +----------------------------------------------------------------------+   | Author : Marc Boeren         <marc@guidance.nl>                      |   +----------------------------------------------------------------------+*//* $Id: dbx.c,v 1.42.2.2.8.2 2007/01/01 09:46:41 sebastian Exp $ */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "php.h"#include "php_ini.h"#include "php_dbx.h"#include "ext/standard/info.h"/* defines for supported databases */#define DBX_UNKNOWN 0#define DBX_MYSQL 1#define DBX_ODBC 2#define DBX_PGSQL 3#define DBX_MSSQL 4#define DBX_FBSQL 5#define DBX_OCI8 6#define DBX_SYBASECT 7/* includes for supported databases */#include "dbx.h"#include "dbx_mysql.h"#include "dbx_odbc.h"#include "dbx_pgsql.h"#include "dbx_mssql.h"#include "dbx_fbsql.h"#include "dbx_oci8.h"#include "dbx_sybasect.h"/* support routines */int module_exists(char *module_name){	zend_module_entry *zme;	int r;	r = zend_hash_find(&module_registry, module_name, strlen(module_name)+1, (void **) &zme);	return r==0?1:0;}int module_identifier_exists(long module_identifier){	switch (module_identifier) {		case DBX_MYSQL: return module_exists("mysql");		case DBX_ODBC: return module_exists("odbc");		case DBX_PGSQL: return module_exists("pgsql");		case DBX_MSSQL: return module_exists("mssql");		case DBX_FBSQL: return module_exists("fbsql");		case DBX_OCI8: return module_exists("oci8");		case DBX_SYBASECT: return module_exists("sybase_ct");	}	return 0;}int get_module_identifier(char *module_name){	if (!strcmp("mysql", module_name)) return DBX_MYSQL;	if (!strcmp("odbc", module_name)) return DBX_ODBC;	if (!strcmp("pgsql", module_name)) return DBX_PGSQL;	if (!strcmp("mssql", module_name)) return DBX_MSSQL;	if (!strcmp("fbsql", module_name)) return DBX_FBSQL;	if (!strcmp("oci8", module_name)) return DBX_OCI8;	if (!strcmp("sybase_ct", module_name)) return DBX_SYBASECT;	return DBX_UNKNOWN;}int split_dbx_handle_object(zval **dbx_object, zval ***pdbx_handle, zval ***pdbx_module, zval ***pdbx_database TSRMLS_DC){	convert_to_object_ex(dbx_object);	if (zend_hash_find(Z_OBJPROP_PP(dbx_object), "handle", 7, (void **) pdbx_handle)==FAILURE	|| zend_hash_find(Z_OBJPROP_PP(dbx_object), "module", 7, (void **) pdbx_module)==FAILURE	|| zend_hash_find(Z_OBJPROP_PP(dbx_object), "database", 9, (void **) pdbx_database)==FAILURE) {		return 0;	}	return 1;}/* from dbx.h, to be used in support-files (dbx_mysql.c etc...) */void dbx_call_any_function(INTERNAL_FUNCTION_PARAMETERS, char *function_name, zval **returnvalue, int number_of_arguments, zval ***params){	zval *zval_function_name;	MAKE_STD_ZVAL(zval_function_name);	ZVAL_STRING(zval_function_name, function_name, 1);	if (call_user_function_ex(EG(function_table), NULL, zval_function_name, returnvalue, number_of_arguments, params, 0, NULL TSRMLS_CC) == FAILURE) {		zend_error(E_ERROR, "function '%s' not found", Z_STRVAL_P(zval_function_name));	}	zval_dtor(zval_function_name); /* to free stringvalue memory */	FREE_ZVAL(zval_function_name);}/* switch_dbx functions declarations * each must be supported in the dbx_module files as dbx_module_function, *   e.g. switch_dbx_connect expects a dbx_mysql_connect in de dbx_mysql files *   all params except the dbx_module param are passed on * each must return the expected zval *'s in the rv parameter, which are passed on unmodified * do NOT use the return_value parameter from INTERNAL_FUNCTION_PARAMETERS * you can additionally return 0 or 1 for failure or success which will also be returned by the switches */int switch_dbx_connect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns connection handle as resource on success or 0 as long on failure */int switch_dbx_pconnect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns persistent connection handle as resource on success or 0 as long on failure */int switch_dbx_close(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns 1 as long on success or 0 as long on failure */int switch_dbx_query(zval **rv, zval **dbx_handle, zval **db_name, zval **sql_statement, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns 1 as long or result identifier as resource on success or 0 as long on failure */int switch_dbx_getcolumncount(zval **rv, zval **result_handle, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns column-count as long on success or 0 as long on failure */int switch_dbx_getcolumnname(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns column-name as string on success or 0 as long on failure */int switch_dbx_getcolumntype(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns column-type as string on success or 0 as long on failure */int switch_dbx_getrow(zval **rv, zval **result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns array[0..columncount-1] as strings on success or 0 as long on failure */int switch_dbx_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns string */int switch_dbx_esc(zval **rv, zval **dbx_handle, zval **string, INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);	/* returns escaped string *//* Every user visible function must have an entry in dbx_functions[].*/function_entry dbx_functions[] = {	ZEND_FE(dbx_connect,	NULL)	ZEND_FE(dbx_close,		NULL)	ZEND_FE(dbx_query,		NULL)	ZEND_FE(dbx_error,		NULL)	ZEND_FE(dbx_escape_string,	NULL)	ZEND_FE(dbx_sort,		NULL)	ZEND_FE(dbx_compare,	NULL)	{NULL, NULL, NULL} /* Must be the last line in dbx_functions[] */};zend_module_entry dbx_module_entry = {    STANDARD_MODULE_HEADER,	"dbx",	dbx_functions,	ZEND_MINIT(dbx),	ZEND_MSHUTDOWN(dbx),	NULL, /*ZEND_RINIT(dbx),         Replace with NULL if there's nothing to do at request start */	NULL, /*ZEND_RSHUTDOWN(dbx),     Replace with NULL if there's nothing to do at request end */	ZEND_MINFO(dbx),    NO_VERSION_YET,	STANDARD_MODULE_PROPERTIES};#ifdef COMPILE_DL_DBXZEND_GET_MODULE(dbx)#endifZEND_INI_BEGIN()    ZEND_INI_ENTRY("dbx.colnames_case", "unchanged", ZEND_INI_SYSTEM, NULL)ZEND_INI_END()ZEND_MINIT_FUNCTION(dbx){    REGISTER_INI_ENTRIES();	REGISTER_LONG_CONSTANT("DBX_MYSQL", DBX_MYSQL, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_ODBC", DBX_ODBC, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_PGSQL", DBX_PGSQL, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_MSSQL", DBX_MSSQL, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_FBSQL", DBX_FBSQL, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_OCI8", DBX_OCI8, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_SYBASECT", DBX_SYBASECT, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_PERSISTENT", DBX_PERSISTENT, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_RESULT_INFO", DBX_RESULT_INFO, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_RESULT_INDEX", DBX_RESULT_INDEX, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_RESULT_ASSOC", DBX_RESULT_ASSOC, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_COLNAMES_UNCHANGED", DBX_COLNAMES_UNCHANGED, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_COLNAMES_UPPERCASE", DBX_COLNAMES_UPPERCASE, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_COLNAMES_LOWERCASE", DBX_COLNAMES_LOWERCASE, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_CMP_NATIVE", DBX_CMP_NATIVE, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_CMP_TEXT", DBX_CMP_TEXT, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_CMP_NUMBER", DBX_CMP_NUMBER, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_CMP_ASC", DBX_CMP_ASC, CONST_CS | CONST_PERSISTENT);	REGISTER_LONG_CONSTANT("DBX_CMP_DESC", DBX_CMP_DESC, CONST_CS | CONST_PERSISTENT);	return SUCCESS;}ZEND_MSHUTDOWN_FUNCTION(dbx){    UNREGISTER_INI_ENTRIES();	return SUCCESS;}/* Remove if there's nothing to do at request start *//*ZEND_RINIT_FUNCTION(dbx){	return SUCCESS;}*//* Remove if there's nothing to do at request end *//*ZEND_RSHUTDOWN_FUNCTION(dbx){	return SUCCESS;}*/ZEND_MINFO_FUNCTION(dbx){	php_info_print_table_start();	php_info_print_table_row(2, "dbx support", "enabled");	php_info_print_table_row(2, "dbx version", "1.0.0");	php_info_print_table_row(2, "supported databases", "MySQL\nODBC\nPostgreSQL\nMicrosoft SQL Server\nFrontBase\nOracle 8 (oci8)\nSybase-CT");	php_info_print_table_end();    DISPLAY_INI_ENTRIES();}/*	actual implementation of the dbx functions*//* {{{ proto dbx_link_object dbx_connect(string module_name, string host, string db, string username, string password [, bool persistent])   Returns a dbx_link_object on success and returns 0 on failure */ZEND_FUNCTION(dbx_connect){	int number_of_arguments=5;	zval **arguments[6];	int result;	long module_identifier;	zval *dbx_module;	zval *db_name;	zval *rv_dbx_handle;	int persistent=0;	if ( !(ZEND_NUM_ARGS()==number_of_arguments+1 || ZEND_NUM_ARGS()==number_of_arguments) || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), arguments) == FAILURE) {		WRONG_PARAM_COUNT;	}	if (ZEND_NUM_ARGS()==number_of_arguments+1) {		convert_to_long_ex(arguments[5]);		if (Z_LVAL_PP(arguments[5])!=0) persistent=1;	}	if (Z_TYPE_PP(arguments[0]) == IS_LONG) {		if (!module_identifier_exists(Z_LVAL_PP(arguments[0]))) {			zend_error(E_WARNING, "dbx: module '%ld' not loaded or not supported.", Z_LVAL_PP(arguments[0]));			return;		}		module_identifier = Z_LVAL_PP(arguments[0]);	} else {		convert_to_string_ex(arguments[0]);		if (!module_exists(Z_STRVAL_PP(arguments[0]))) {			zend_error(E_WARNING, "dbx: module '%s' not loaded.", Z_STRVAL_PP(arguments[0]));			return;		}		module_identifier=get_module_identifier(Z_STRVAL_PP(arguments[0]));		if (!module_identifier) {			zend_error(E_WARNING, "dbx: unsupported module '%s'.", Z_STRVAL_PP(arguments[0]));			return;		}	}	MAKE_STD_ZVAL(dbx_module); 	ZVAL_LONG(dbx_module, module_identifier);	MAKE_STD_ZVAL(rv_dbx_handle); 	ZVAL_LONG(rv_dbx_handle, 0);	convert_to_string_ex(arguments[1]);	convert_to_string_ex(arguments[2]);	convert_to_string_ex(arguments[3]);	convert_to_string_ex(arguments[4]);	MAKE_STD_ZVAL(db_name); 	ZVAL_STRING(db_name, Z_STRVAL_PP(arguments[2]), 1);	if (persistent) {		result = switch_dbx_pconnect(&rv_dbx_handle, arguments[1], arguments[2], arguments[3], arguments[4], INTERNAL_FUNCTION_PARAM_PASSTHRU, &dbx_module);	} else {		result = switch_dbx_connect(&rv_dbx_handle, arguments[1], arguments[2], arguments[3], arguments[4], INTERNAL_FUNCTION_PARAM_PASSTHRU, &dbx_module);	}	if (!result) {		FREE_ZVAL(dbx_module);		zval_dtor(db_name); /* to free stringvalue memory */		FREE_ZVAL(db_name);		FREE_ZVAL(rv_dbx_handle);		RETURN_LONG(0);	}

⌨️ 快捷键说明

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