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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.