Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,191,969 members, 7,946,202 topics. Date: Wednesday, 11 September 2024 at 02:17 PM

Dual Dbase Connection Script - Another Easy Way Out - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Dual Dbase Connection Script - Another Easy Way Out (752 Views)

Easy Way To Add A Paypal Donate Button In Blogger / Easy way to earn 15-20 dollars daily / Which Is The Fastest Internet Connection In Nigeria (2) (3) (4)

(1) (Reply)

Dual Dbase Connection Script - Another Easy Way Out by Nobody: 12:19pm On Mar 01, 2009
In this scenario, you are developing a website offline and you also have an online copy. Now for some reasons, you have
different logins for the database.
Some people will create user accounts for the database so that the same username and passwords will exist for the database
on the internet and local servers. Some will change the username/password whenever they upload it.
Anyone, they all get the same results.

I recommend that, if the username / password of your local and internet servers are different, try out this script.

connect.php
<?php
function sonline() {if ($_SERVER['SERVER_NAME']=="localhost"||$_SERVER['SERVER_NAME']=="127.0.0.1"||strtolower($_SERVER['SERVER_NAME'])==strtolower(getenv('COMPUTERNAME'))) {return false;} else {return true;}}

if(sonline()) {
//internet server config
$username="internet";
$password="google";
} else {
//local server config
$username="root";
$password="password";
}

$link = mysql_connect('localhost', "$username", "$password"wink;
if (!$link) {die('Could not connect to mysql server. Check your account settings! ' . mysql_error());}

mysql_select_db("dhtmlproject",$link) or die ("Could not select database"wink;
?>
Re: Dual Dbase Connection Script - Another Easy Way Out by Nobody: 12:22pm On Mar 01, 2009
I must quickly point out that the method is not fool proof. Because some servers make use of 127.0.0.2 or any other one. Common one is localhost and also 127.0.0.1 But again, study the sonline function. So that if your server is different, just put the IP address there.
It is a very simple technique really - just might come in handy atimes.
Re: Dual Dbase Connection Script - Another Easy Way Out by Nobody: 12:51pm On Mar 01, 2009
connect.php
<?php
function sonline() {if ($_SERVER['SERVER_NAME']=="localhost"||$_SERVER['SERVER_NAME']=="127.0.0.1"||strtolower($_SERVER['SERVER_NAME'])==strtolower(getenv('COMPUTERNAME'))) {return false;} else {return true;}}
if(sonline()) {
//internet server config
$username="internet";
$password="google";
$dbase="$username_dhtmlproject";
} else {
//local server config
$username="root";
$password="password";
$dbase="dhtmlproject";
}

$link = mysql_connect('localhost', "$username", "$password"wink;
if (!$link) {die('Could not connect to mysql server. Check your account settings! ' . mysql_error());}

mysql_select_db("$dbase",$link) or die ("Could not select database"wink;
?>



This modification is for some servers that when you are online, the name of the dbase will the the username_dbase.
Whatever the kind of server u are using, u can alwayz modify it to work.

(1) (Reply)

Tell Us What You Want & Your Website Is Up In 24 Hours / Selling For Accountants & Consultants / Website Traffic Generation Made So Easy

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.