Jump to content

dbconnect.php


rajeshkumarvm

Recommended Posts

<?php

$db_host = "localhost";

$db_user = "root";

$db_pwd = "rajesh";

$db_dbname = "test";

 

mysql_connect($db_host, $db_user, $db_pwd) or die("Could not connect: " . mysql_error());

$seldb = mysql_select_db($db_dbname) or die("Could not connect: " . mysql_error()) ;

?>

 

This is my actual page.In this page i dont want to view the "root","rajesh" to any other third persons.Now i dont want the dll function.Any one can say

how to work with page?.I am waiting for encryption and decryption or any other methods also.But any way this username and password wont display

others.Orelse any way to work with mysql server for this

Link to comment
https://forums.phpfreaks.com/topic/72815-dbconnectphp/
Share on other sites

Nobody will see this as long as you don't give the source file to other or tell the password and infos urself.

 

The best way is to define the variables in a constant file and include that file in your connection page.

 

For e.g I have a constant.php file , here i store my passwords and other things...

 

define ('SERVERHOST','localhost' );

define ('SERVERUSER','myserver' );

define ('SERVERPASSWORD','c#nRnI_Ec$e' );

define ('SERVERDATABASE','myserverdb' );

define ('LOCALRHOST','localhost' );

define ('LOCALUSER','root' );

define ('LOCALPASSWORD','mylocalpwd' );

define ('LOCALDATABASE','mydb' );

 

 

And I have another file db.inc.php where I use those constants to connect.

 

<?php

// db.inc.php
// connect to databse 

//-------- for Local Server-----------//

$sLocalHost=LOCALRHOST;
$sServerHost=SERVERHOST;
$sLocalUser = LOCALUSER;
$sLocalPassword = LOCALPASSWORD;
$sServerUser = SERVERUSER;
$sServerPassword = SERVERPASSWORD;
$sServerDatabaseName = SERVERDATABASE;
$sLocalDatabaseName = LOCALDATABASE;
$conn = @mysql_connect($sServerHost,$sServerUser,$sServerPassword);
if(!$conn) {
$conn = mysql_connect($sLocalHost,$sLocalUser,$sLocalPassword);
}
//$con=  mysql_connect("localhost","root"); //On Local Server
$db=mysql_select_db($sServerDatabaseName);
if(!$db){
$db=mysql_select_db($sLocalDatabaseName);
}
//----------------------------------------//

if($conn=="")
{
  trigger_error('Unable to connect to database: ' . mysql_error());
}

?>

 

And then I have a config.php file where I include this connection .. and I include this config.php in all php pages that's all.

 

Hope it helps ;)

Link to comment
https://forums.phpfreaks.com/topic/72815-dbconnectphp/#findComment-367227
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.