472,789 Members | 1,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

function aliases

Hi,

I have to write a dynamic page which has to run on several platforms, using
different databases. Because of that, I want to write a small db-front-end
which is an almost 1-on-1 mapping of the functions provided by the PHP API
(and the proper front-end is loaded using a conditional include).

Using the "C-way", I thought of using define(), but in PHP that can only be
used for defining constants. I also though of using function variables, but
then the feel of the code changes.

The simplest method I have found sofar is the following (for mysql_connect):

function sql_connect()
{
$p = func_get_args();
return ( call_user_func_array('mysql_connect', $p) );
}

Anybody got any other ideas?

Thanks,
--
Martijn
http://www.sereneconcepts.nl
Jul 17 '05 #1
2 1772
Martijn wrote:

The simplest method I have found sofar is the following (for
mysql_connect):

function sql_connect()
{
$p = func_get_args();
return ( call_user_func_array('mysql_connect', $p) );
}

Anybody got any other ideas?

Thanks,


You might define a handful of classes, one for each db platform, all of
which have the same functions (*query, *fetch_array etc). That is a nice
"oopy" way to do things.

If you have no great love of object-orientation, you just have a file with
lots of switches in it. Which, IHMO, is much easier to maintain:

function sql_connect()
{
$p = get_env_variable("platform");
switch ($platform) {
case ('mysql'):
return whatever();
break;
case ('postgres'):
...
default:
return false;
}
}
Its the same typing in either case, but in the latter you have everything in
one place where you can see it.
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #2
Hi Kenneth,

Thank you very much for your thoughts.
The simplest method I have found sofar is the following (for
mysql_connect):

function sql_connect()
{
$p = func_get_args();
return ( call_user_func_array('mysql_connect', $p) );
}

Anybody got any other ideas?
You might define a handful of classes, one for each db platform, all
of which have the same functions (*query, *fetch_array etc). That is
a nice "oopy" way to do things.


That would be a nice thing to do. No problem with OO, but it is just that I
am looking for a quick (and non-OO) way to do this. For my bigger projects
I usually have some stub-objects to communicate with the database.
If you have no great love of object-orientation, you just have a file
with lots of switches in it. Which, IHMO, is much easier to maintain:

[code snipped]

Its the same typing in either case, but in the latter you have
everything in one place where you can see it.


Its not the problem with the conditional includes that I am having, in fact,
I could still apply the switch approach using the above method (in fact, the
switches are there, but just one level higher - this also has the advantage
that it needs to be called only once for each script, and not on each
invocation of a database function). If anyone is interested, it is like
this:

switch ( DBTYPE )
{
case ( 'mysql' ): include_once('db_mysql.inc.php'); break;
case ( 'mssql' ): include_once('db_mssql.inc.php'); break;
}

(in fact, I have thought about making one statement:

include_once('db_'.DBTYPE.'.inc.php');

but this has the advantage that you see which dbs are supported)

What I am having problems with is easily/efficiently setting up a function
alias.

But thanks again!

--
Martijn
http://www.sereneconcepts.nl
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Ash | last post by:
I recently had a project dropped into my lap that is written in JSP running on Apache/Resin. A previous version of the application is already running and configured on the production server, but...
0
by: Andrew | last post by:
With command-line interface ( 3.23.37, UNIX Socket ) all is well with column aliasing. However, column aliases disappear in Excel, over ODBC, when there are multiple (joined) tables in the query. ...
5
by: Kevin | last post by:
I'm making my first attempt to put embedded SQL in a visual C++ application and I'm having trouble getting aliases to work. If I try the following SQL query on MS SQL 7.0 it works fine. SELECT...
0
by: Krzysiek | last post by:
Hi all, I have an issue with QSYS\QADBXREF file - it keeps aliases on tables. I take care of an application that works on many places (servers) and on one of them it's not possible to create...
22
by: mp | last post by:
i have a python program which attempts to call 'cls' but fails: sh: line 1: cls: command not found i tried creating an alias from cls to clear in .profile, .cshrc, and /etc/profile, but none...
15
by: jacob navia | last post by:
Recently, we had a very heated thread about GC with the usual arguments (for, cons, etc) being exchanged. In one of those threads, we came into the realloc problem. What is the realloc...
22
by: Daniel Rucareanu | last post by:
I have the following script: function Test(){} Test.F = function(){} Test.F.FF = function(){} Test.F.FF.FFF = function(){} Test.F.FF.FFF.FFFF = function(){} //var alias = function(){}; var...
11
by: Chris Thomasson | last post by:
I was thinking of how I was going to create a robust versioning system in Standard C++ for my library and was wondering exactly what the point of a namespace alias is? The seem like a rather...
1
by: drexcol | last post by:
I am a php newbie and am trying to write a script that will direct visitors to specific pages on my website based on which of several url’s they have entered (all are aliases of the main website)....
6
by: dom.k.black | last post by:
Is it still common practice to use type aliases (INT, PCHAR etc). It looks ugly and breaks the syntax highlighting, are there any advantages these days (MSVC++6.0 and later)? I could understand...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.