Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

[HOWTO] PHP + MySQL on a mixed environment

8:10 am on Apr 2, 2010 (gmt 0)

New User

5+ Year Member

joined:Jan 8, 2010
posts: 18
votes: 0

If you're - like me
- working on a project on your local windows machine, - want to regulary put your newly updated code on your linux webhost
- don't bother to always change the database and security settings on your local mysql daemon on every reinstall

this small script might help you.

function lib_mysql_connectdb($db)
$db_host= "localhost";
$db= $db;

if (file_exists("c:\WINDOWS\win.ini")) // we're on WINDOWS
$db_user= "root";
$db_pass= "";
else// we're on LINUX
$db_pass= "mr.Pas.Sword";
$db_user= $db;

$mysqllink= @mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
@mysql_select_db($db) or die(mysql_error());
return $mysqllink;
7:43 pm on Apr 2, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 24, 2005
votes: 0

Just to add to your effort, you can put yout DB connection code in an include file seperately, and have that uploaded once to your server. Local copy contains your windows host values and server copy contains your server mysql values, and your script includes that file. That way you wont have to change things on every upload. Just another way to do the same thing