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

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.
Who is Participating?
VoteyDiscipleConnect With a Mentor Commented:
There are only four files included from there, so one must contain the connection information:


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.
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:

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.
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.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

rich_75035Author Commented:
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.
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?
rich_75035Author Commented:
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?


/* (c)2006, Visitech Solutions, LLC. All rights reserved.                         */
/* Written by Developer (                        */
/* 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.

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


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

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

$CFG->support          = ""; // client's support address
$CFG->webmaster        = "Developer"; // webmaster's name
$CFG->webmasterEmail   = ""; // webmaster's email
$CFG->supportEmail     = ""; // 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 ("; // 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 **************************/


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

$USER->firstName = '';
$USER->lastName = '';
$USER->privId = '';
$USER->privIdLevel = '';
$USER->email = '';
$USER->id = '';
$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

// 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

// 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; }

// 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

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)) {

/*************** 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 feature


rich_75035Author Commented:
That's it!!  I don't know how but I missed csi.php..  That's where it is.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.