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

📄 phpdbdriver.c

📁 Coware的LISA指令集描述语言开发包
💻 C
字号:
#include "phpdbdriver.h"

#include <stdio.h>



// writeMySQLdriver
//	This function will create the dbsupport file for MySQL
//	database engine. The previous file will be overwritten.
void writeMySQLdriver( char *hostname, char *dbname, char *username, char *password )
{
	FILE *f;

	// create the file, overwritting the existing...
	f = fopen( "dbsupport.php", "w" );
	if ( !f )
		error( "Cannot create database driver file." );

	fprintf( f, "<?\n" );
	fprintf( f, "function _close_()\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\tmysql_close( $_link_ );\n" );
	fprintf( f, "}//_close_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _commit_()\n" );
	fprintf( f, "{\n" );
	fprintf( f, "}//_commit_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _database_()\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\t$_link_ = mysql_connect( '%s', '%s', '%s' );\n", hostname, username, password );
	fprintf( f, "\tmysql_select_db( '%s', $_link_ );\n", dbname );
	fprintf( f, "}//_database_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _fetch_( $result )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_array_;\n" );
	fprintf( f, "\t$_array_ = mysql_fetch_array( $result );\n" );
	fprintf( f, "}//_fetch_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _foreach_( $result )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\treturn mysql_num_rows( $result );\n" );
	fprintf( f, "}//_foreach_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _scan_( $result, $id )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_array_;\n" );
	fprintf( f, "\treturn $_array_[ $id ];\n" );
	fprintf( f, "}//_scan_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _transaction_()\n" );
	fprintf( f, "{\n" );
	fprintf( f, "}//_transaction_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _dbEmpty( $result )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\treturn ( !$result ? true : mysql_num_rows( $result ) == 0 );\n" );
	fprintf( f, "}//dbEmpty()\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _dbQuery( $command )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\t// mysql query should not end with a semicolon...\n" );
	fprintf( f, "\t$command = trim( $command );\n" );
	fprintf( f, "\tif ( substr( $command, -1 ) == ';' )\n" );
	fprintf( f, "\t{\n" );
	fprintf( f, "\t\t$command = substr( $command, 0, strlen( $command ) - 1 );\n" );
	fprintf( f, "\t}\n" );
	fprintf( f, "\t$result = mysql_query( $command, $_link_ ) or die( 'Error while SQL query: ' . $command );\n" );
	fprintf( f, "\treturn $result;\n" );
	fprintf( f, "}//dbQuery\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _dbSql( $command )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\t// mysql query should not end with a semicolon...\n" );
	fprintf( f, "\t$command = trim( $command );\n" );
	fprintf( f, "\tif ( substr( $command, -1 ) == ';' )\n" );
	fprintf( f, "\t{\n" );
	fprintf( f, "\t\t$command = substr( $command, 0, strlen( $command ) - 1 );\n" );
	fprintf( f, "\t}\n" );
	fprintf( f, "\tmysql_query( $command, $_link_ ) or die( 'Error while SQL command: ' . $command );\n" );
	fprintf( f, "}//dbSql\n" );
	fprintf( f, "?>\n" );

	// all done...
	fclose( f );
}//writeMySQLdriver





// writeODBCdriver
//	This function will create the dbsupport file for ODBC
//	database engine. The previous file will be overwritten.
void writeODBCdriver( char *dsn, char *username, char *password )
{
	FILE *f;

	// create the file, overwritting the existing...
	f = fopen( "dbsupport.php", "w" );
	if ( !f )
		error( "Cannot create database driver file." );

	fprintf( f, "<?\n" );
	fprintf( f, "function _close_()\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\todbc_close( $_link_ );\n" );
	fprintf( f, "}//_close_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _commit_()\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\todbc_commit( $link );\n" );
	fprintf( f, "\todbc_autocommit( $_link_, true );\n" );
	fprintf( f, "}//_commit_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _database_()\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\t$_link_ = odbc_connect( '%s', '%s', '%s' )\n", dsn, username, password );
	fprintf( f, "\t\tor die( '<H3>ERROR:</H3><BR>Cannot connect to database.<BR>' );\n" );
	fprintf( f, "}//_database_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _fetch_( $result )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_array_;\n" );
	fprintf( f, "\todbc_fetch_into( $result, $_array_ );\n" );
	fprintf( f, "}//_fetch_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _foreach_( $result )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\treturn odbc_num_rows( $result );\n" );
	fprintf( f, "}//_foreach_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _scan_( $result, $id )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\treturn odbc_result( $result, $id+1 );\n" );
	fprintf( f, "}//_scan_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _transaction_()\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\todbc_autocommit( $_link_, false );\n" );
	fprintf( f, "}//_transaction_\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _dbEmpty( $result )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\treturn ( !$result ? true : odbc_num_rows( $result ) == 0 );\n" );
	fprintf( f, "}//dbEmpty()\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _dbQuery( $command )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\t$result = odbc_exec( $_link_, $command )\n" );
	fprintf( f, "\t\tor die( 'Error while SQL query: ' . $command );\n" );
	fprintf( f, "\treturn $result;\n" );
	fprintf( f, "}//dbQuery\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "\n" );
	fprintf( f, "function _dbSql( $command )\n" );
	fprintf( f, "{\n" );
	fprintf( f, "\tglobal $_link_;\n" );
	fprintf( f, "\todbc_exec( $command, $_link_ )\n" );
	fprintf( f, "\t\tor die( 'Error while SQL command: ' . $command );\n" );
	fprintf( f, "}//dbSql\n" );
	fprintf( f, "?>\n" );

	// all done...
	fclose( f );
}//writeODBCdriver

⌨️ 快捷键说明

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