Forum Moderators: coopster

Message Too Old, No Replies

Developing for Windows and Unix

         

eelixduppy

7:03 pm on Jan 16, 2009 (gmt 0)



There are a few things that are different between the two when it comes to developing for both for cross-compatibility and I'd like to create a list of things that should be addressed when making an application that is compatible with both Windows and Unix servers.

To get this thing going I'll add a few things in here...


1) Newline representation on Windows is

\r\n
where on Unix it is just
\n
(also different for Mac:
\r
).


2) Accounting for differences between databases (MSSQL and MySQL). A solution to this might be to use variable functions [php.net] for all the database functions (set in a config file).

For example:



if($db == 'mysql') {
$db_connect = 'mysql_connect';
....
}
else if($db == 'mssql') {
$db_connect = 'mssql_connect';
....
}
$link = $db_connect('localhost','username','password');


What do you have?

enigma1

11:38 am on Jan 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have to use multiple databases perhaps one way is to use wrappers and separate classes to achieve data abstraction.

So if we assume the web app is aware of a $db_obj object and 3 wrapper functions db_connect, db_query, db_close then the db interface could be:

switch($db) {
case 'mssql':
require_once('ms_sql');
$db_obj = new ms_sql;
break;
case: 'mysql':
default:
require_once('my_sql');
$db_obj = new my_sql;
break;
}

and each of the dbase classes includes a set of wrappers for the web app with connect being one of them

$db_obj->connect('localhost','username','password');
and the link can be stored as a member var of the db class if ever needed by the higher layer,
$link = $db_obj->get_link();

coopster

11:52 pm on Jan 21, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Here's one ...

PATH_SEPARATOR and DIRECTORY_SEPARATOR

$pathName = stristr(PHP_OS, 'WIN') ? str_replace(DIRECTORY_SEPARATOR, '/', $file->getPathname()) : $file->getPathname();