Solved

Moving PHP and MYSQL to a new host.  Also MYSQL DB name had to be changed.  Now PHP doesn't work.

Posted on 2006-11-15
7
281 Views
Last Modified: 2008-03-06
Let me start by saying that I am not a PHP developer.  We hired an outside developer to create a site for us using PHP and a MYSQL database.  We have deceided to move to a different hosting company and the hosting company that we chose required that we use a different database name for our MYSQL database.  We'll of course now the site doesn't work.  In addition, I think that some variables need to be changed because we also changed our domain name and I see the old domain name referenced in the code.  So....there are probably quite a few changes that need to be made but this is way above my level of PHP knowledge.

I need someone who can look at the code and let me know where I need to change the db name.  I have tried but it's a little confusing because the tables in the database are named similar to the db name.

Obviously I can't post all of the code here so I may need to provide someone with a temporary ftp password to look at the code.
0
Comment
Question by:rich_75035
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17948414
There are three different ways to select which database to use in PHP: one way that will make your life really easy, and two that will bring up a really strong desire to have the outside developer taken out and flogged.

Search, in the code, for a line like:
 mysql_db_name('old_name');

If that's in there (probably only once in the entire site) you can just change old_name to new_name and you're set.
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17948446
If mysql_db_name is nowhere to be found, then the next most likely way it was done is with mysql_db_query() -- lots and lots of calls to mysql_db_query(), all looking something like:
mysql_db_query('big long ugly query', 'old_name');

In that case you'd have to change ALL those calls.


If even THAT isn't found, then the only thing I can think would make this work is if all the queries were written like:

mysql_query('SELECT column_name FROM old_name.table_name.....');

And in that case you'd have to edit the individual queries -- a pretty big task.  Honestly the first (easy) solution is most likely to work, but I'm sure you can see where the sudden desire for violent retaliation would spring up if it were done either of these other ways.



As to the domain name we'd have to see a little more of how that's used.  I'd definitely recommend against setting up such an FTP password, since you'd still have to post that here publicly and it'd be way more access than desired.  Most likely all we'd need to see is the code you've noticed refering to the domain name and we could probably figure it out from there.
0
 

Author Comment

by:rich_75035
ID: 17948522
I used UltraEdit to search all of the PHP code and found no instances of 'mysql_db_name' in any of the files.  The is an includes directory that appears to contain several files that setup the environmental variables.  But nothing stands out to me as the database name.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17948582
Even if the actual name of the database is defined in an environment variable there'd still have to be a call to mysql_db_name or mysql_db_query or (if you're supremely unlucky) just mysql_query() with the database name built-in.

(I should point out that mysql_query() may well be used in a perfectly ordinary and non-headache-inspiring way; it's just if the database name is embedded in the queries that it gets supremely annoying.)

So, if there's no mysql_db_name, are there a lot of mysql_db_query() calls floating around?
0
 

Author Comment

by:rich_75035
ID: 17953142
Here is an example of the code..  This is an include file called setting.php that he calls from the very first page, login.php..   Can you tell how he's calling the db from this?

Code:

<?php
/******************************************************************************/
/* (c)2006, Visitech Solutions, LLC. All rights reserved.                         */
/* Written by Developer (support@visitechsolutions.com)                        */
/* This file is not authorized for reuse, resale, or publication on any site  */
/* other than Visitech Solutions                                                  */
/******************************************************************************/

// We're going to create a master object here that will contain all
// site configuration information
class object {};
$CFG = new object;

// Feature switches;
$CFG->trackBotVisits = false;  // set to true to track bot hits; useful to see if
                               // search engines are spidering your entire site.
                                                                                   // Warning: this can make the log db table grow quite large
                                                                                   //          when left on for long periods of time.

// strong validation prevents duplicate e-mail addresses in the registration process
$CFG->strongValidation = true; // set to true if the site is live; false if in development

/************************* LOCATION ***************************/

// The location flag tells the system where it is (e.g. on a test
// server or on the live site.  For convienence in Dreamweaver, we place
// this file in it's own cloaked directory so DW's synchronize function
// skips it.  The variable $testserver is found in this file.
@include_once('location/location.php');

/************************ BEGIN TO DO *************************/

require_once('paths.php');

$today = getdate();
$CFG->year = $today['year'];      // used for Copyright date

/************************ BEGIN TO DO *************************/

$CFG->support          = "support@visitechsolutions.com"; // client's support address
$CFG->webmaster        = "Developer"; // webmaster's name
$CFG->webmasterEmail   = "support@visitechsolutions.com"; // webmaster's email
$CFG->supportEmail     = "support@visitechsolutions.com"; // client's tech support email
$CFG->webAdmin         = array(1, 3); // an array containing the record ids from csi_users of the webmasters
$CFG->author           = "Developer (support@visitechsolutions.com)"; // your name & contact info
$CFG->client           = "Visitech Solutions"; // the name of your client's company; will appear on communications & copyrights
$CFG->clientSite       = "Visitech Solutions"; // the name of the client's domain; will appear on communications & copyrights
$CFG->copyright        = "&copy;".$CFG->year.", ".$CFG->client.". All rights reserved."; // meta tag & page footers
$CFG->webmasterphone   = "469.688.3600"; // webmaster's phone

$CFG->minAdmin         = 900000000; // the minimum privId of your site Administrators
$CFG->fieldRepPrivId   = 900000000; // the privId of a Field Representative
$CFG->minAdminMenu     = 900000100; // the minimum privId of your site Administrators
$CFG->managerPrivId    = 900000100; // the privId of an Employee Manager
$CFG->payrollPrivId    = 900001000; // the privId of a Payroll Manager
$CFG->compayManager    = 900010000; // the privId of a Company Manager
$CFG->superAdmin       = 999999999; // the privId of a Super-Administrator

$CFG->minUsernameLen   = 4; // the minimum lenght of a valid site username
$CFG->minPWLen         = 6; // the minimum lenght of a valid site password

$CFG->siteTitle        = "Visitech Solutions"; // Site's name; will appear on all page headers
$CFG->siteTag          = "TBD"; // Site's tag line; will appear on all page headers
$CFG->siteDescription  = "TBD"; // meta-tag
$CFG->siteKeywords     = "TBD"; // meta-tag; optionally replace these on each page for better search engine results
$CFG->siteAuthor       = $CFG->author.' on behalf of '.$CFG->client; // meta-tag; no need to change
$CFG->seperator        = "&nbsp;&nbsp;/&nbsp;&nbsp;";  // used for consistency in separating breadcrumb and submenu items
// switches

/************************* END TO DO **************************/

/************************* MENU ITEMS *************************/
// Menus are crated in the mainMenu class in classes_common.php
// $MENU->[menu] array members:
//         array('[Menu Label]', '[title]', [page url], [min privId], [privId condition])
//       [0] Button label
//       [1] Title (a.k.a. 'tool tip')
//       [2] url
//       [3] min privId to view page
//       [4] privId condition:
//           0 - show menu item only if privId == minPriv
//               (e.g. show 'Login' if privId && minPriv both equal 0)
//           1 - show menu item if privId >= minPriv
//               (e.g. show 'Log Out' if privId >= 1 or 'Admin if privId >= 999 (or whatever your minAdmin is)
//           2 - show menu item if privId == minPriv OR privId >= SuperAdmin
//               (e.g. reveals a menu item to a specific user and the SuperAdmin)

$MENU = new object;

$MENU->main =  array(array('Home Page', '', $CFG->wwwroot.'home.php', 0, 1),
                                             array('Bulletin Board', '', $CFG->wwwroot.'news.php', 0, 1),
                                             array('Daily Visit Reports', '', $CFG->wwwroot.'callreports.php', $CFG->fieldRepPrivId, 1),
                                             array('Documents', '', $CFG->wwwroot.'docs/index.php', 0, 1),
                                             array('Register', '', $CFG->wwwroot.'register.php', 0, 0),
                                             array('Log In', '', $CFG->wwwroot.'login.php', 0, 0),
                                             array('Log Out', '', $CFG->wwwroot.'logout.php', 1, 1),
                                             array('My Account', '', $CFG->wwwroot.'myaccount.php', 1, 1));
                                                             
$MENU->admin = array(array('Admin Home', '', $CFG->adminfolder, $CFG->minAdminMenu, 1), /*
                                             array('Visit Report Admin', '', $CFG->adminfolder.'admin_callreports.php', $CFG->managerPrivId, 1), */
                                             array('DB Admin', '', $CFG->adminfolder.'admin_db.php', $CFG->superAdmin, 1),
                                             array('Client Admin', '', $CFG->adminfolder.'admin_clients.php', $CFG->managerPrivId, 1),
                                             array('News Admin', '', $CFG->adminfolder.'admin_news.php', $CFG->minAdminMenu, 1),
                                              array('Regenerate Content', '', $CFG->adminfolder.'admin_regen.php', $CFG->superAdmin, 1),
                                             array('Reports', '', $CFG->adminfolder.'admin_reports.php', $CFG->managerPrivId, 1),
                                             array('Time &amp; Mileage', '', $CFG->adminfolder.'admin_tm.php', $CFG->payrollPrivId, 1),
                                                         array('User Admin', '', $CFG->adminfolder.'admin_users.php', $CFG->managerPrivId, 1));
                                                             
                                                             
/************************** INCLUDES **************************/
include($CFG->cfg.'csi.php');
include($CFG->libdir.'funcs_cookies.php');

require_once($CFG->libdir.'classes_common.php');
require_once($CFG->libdir.'funcs_common.php');


/********************** USER LOGIN INFO ***********************/
$USER = new object;

$USER->firstName = '';
$USER->lastName = '';
$USER->privId = '';
$USER->privIdLevel = '';
$USER->email = '';
$USER->id = '';
$USER->ip = $_SERVER['REMOTE_ADDR'];
$USER->cookie = false;

$loggedIn = false;

// collect browser info
$CFG->browser = browser_detection( 'full');
$CFG->browserStr = $CFG->browser[0].$CFG->browser[2];

// Now, let's gather key information about the site user
session_start();

// If we aren't logged in, look for a cookie.  If found and if valid,
// log the user in automatically.
$cookie = login_cookie($CFG->secretword, $CFG->cookiename);

if(!isset($_SESSION['MM_Username']) && ($cookie['valid']==1)) {
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $cookie['MM_Username'];
    $_SESSION['MM_UserGroup'] = $cookie['MM_UserGroup'];           

    //register the session variables
    session_register("MM_Username");
    session_register("MM_UserGroup");
}

// If we're logged in, get info about the user
if (isset($_SESSION['MM_Username'])) {
  $colname_user = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
      $query_user = "SELECT csi_users.*, csi_priv_ids.csi_priv_idName FROM csi_users LEFT JOIN csi_priv_ids ON csi_users.csi_userPrivId = csi_priv_ids.csi_priv_idLevel WHERE csi_users.csi_userName='".$colname_user."' LIMIT 0,1;";
      $user = mysql_query($query_user, $csi) or die(mysql_error());
      $row_user = mysql_fetch_assoc($user);      
      $totalRows_user = mysql_num_rows($user);
      
      if($totalRows_user > 0) { $loggedIn = true; }
      
      $USER->firstName = $row_user['csi_userFirstName'];
      $USER->lastName = $row_user['csi_userLastName'];
      $USER->privId = $row_user['csi_userPrivId'];
      $USER->privIdLevel = $row_user['csi_priv_idName'];
      $USER->email = $row_user['csi_userEmail'];
      $USER->id = $row_user['csi_userId'];
      if($row_user['csi_userCookie']==1) { $USER->cookie = true; }
      mysql_free_result($user);
}

// write a cookie if the user wants
if($USER->cookie) {
      writeCookie($_SESSION['MM_Username'], $CFG->secretword, $CFG->cookiename);
}

// handle search bots
$CFG->useragentArr = array('googlebot',   // Google
                                                                               'ia_archiver', // alexa
                                                                               'jeeves',      // ask jeeves
                                                                               'baiduspider', // Baiduspider
                                                                               'gamespyhttp', // Gamespy
                                                                               'gigabot',     // Gigabot/Gigablast
                                                                               'inktomi',     // Inktomi
                                                                               'msnbot',      // MSN
                                                                               'scooter',     // Scooter/AltaVista
                                                                               'wget',        // wget
                                                                               'yahoo');      // Yahoo

$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
$CFG->bot = false;
$allowbot = false;
foreach($CFG->useragentArr as $bot) {
      if ( strpos( $useragent, $bot ) !== false ) {
            $CFG->bot = true;

            if($CFG->trackBotVisits) {
                  $allowbot = true;
                  $CFG->thisBot = $bot;
                  if($_SERVER['QUERY_STRING']!='') { $thisPageStr = $pageStr.'?'.$_SERVER['QUERY_STRING']; } else { $thisPageStr = $pageStr; }
                  $insertSQL = sprintf("INSERT INTO csi_log_bots (csi_log_botName, csi_log_botDate, csi_log_botAgent, csi_log_botPage) VALUES (%s, %s, %s, %s)",
                                                                               GetSQLValueString($bot, "text"),
                                                                               GetSQLValueString(epochStamp(), "text"),
                                                                               GetSQLValueString($_SERVER['HTTP_USER_AGENT'], "text"),
                                                                               GetSQLValueString($thisPageStr, "text"));
            
                  $Result1 = mysql_query($insertSQL, $csi) or die(mysql_error());
            } // end if trackBotVisits
            break;
      }
}

// SUPER ADMIN CHECK
if(in_array($USER->id, $CFG->webAdmin)) { $CFG->isSuperAdmin = true; } else { $CFG->isSuperAdmin=false; }


// This reminds you if you're artifically in BOT mode.  In Firefox, type about:config in the url.
// Filter for general.useragent.extra.firefox.  Type in "googlebot" or another bot name (above)
// and reload the site.  You will spoof the system into thinking you're a spider and you will see
// what, in this case, Google sees when they crawl the site.
if($CFG->isSuperAdmin && $allowbot) { echo 'WARNING: You\'re in BOT mode.'; }


if ($testserver==0 && in_array($USER->id, $CFG->webAdmin)) {
      error_reporting(E_ALL);
}

/*************** SYSTEM DEFAULTS - DO NOT CHANGE **************/
$jsRequired     = false;  // set to false by default.  Place at the top of any page
                          // that requires JS (e.g. any admin page) and set to true                                                                              
$fadeStatusMsg  = false;  // set to false by default.  Set to true on a sub-page any
                                                                          // time you have a status message ($statusMsg) that you want
                                                                              // to fade out with the script.aculo.us feature


?>


0
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 500 total points
ID: 17953164
There are only four files included from there, so one must contain the connection information:
include($CFG->cfg.'csi.php');
include($CFG->libdir.'funcs_cookies.php');

require_once($CFG->libdir.'classes_common.php');
require_once($CFG->libdir.'funcs_common.php');

My best guess of the four would be that csi.php


Perhaps the better way to hunt this down is to look for "mysql_connect" which will surely be found somewhere, since there has to be a database connection established.

From that code I'm almost certain there's a mysql_db_name() floating around somewhere that must've been hiding or else overlooked when you hunted for it before.
0
 

Author Comment

by:rich_75035
ID: 17953304
That's it!!  I don't know how but I missed csi.php..  That's where it is.

Thanks..
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now