Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: open

[HOWTO] PHP + MySQL on a mixed environment

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

5+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month