Solved

MySQL is doing bad magic.  Selecting from non-existent table.

Posted on 2014-12-09
5
251 Views
Last Modified: 2014-12-11
I seem to be witnessing the impossible.

I HAD a database with a table named 'table_names', and it had data that showed up correctly when I used it.
Now that DB is gone (c/o phpmyadmin), and XAMPP quit and restarted.

The new database, named as you see below (dbviablitz) has a table of that same name but with different data.

For some unknown reason, the code below is selecting data from a non-existent table and not showing its current contents.

The attached images will help.

HOW am I getting this old data?  VERY eluding, mysterious, and frustrating.



      // Use these values
      $database_host='never mind';
      $username='dbviablitz' ;
      $pswd='no show here' ;
      $database_name='dbviablitz' ;
      
      // Replacing for Ralph's box
// LEFT THIS HERE BUT IT DOES NOTHING.
// I'M INCLUDING MORE THAN I NEED, BUT LOOK FOR ALL CAPS AND YOU'LL FIND THE PERTINENT STUFF
      
      //$database_host='localhost' ;
      /*
      $database_name='blitz1' ;
     $username='blitzadmin';
     $pswd='';
     */
 
 
 
  //
  // Get data from the Form
      if(isset($_POST['invis_task']) )
      {
            $invis_task = $_POST['invis_task'];       //get input text
      }

 
  //
  // Initialize as needed
  // -- -----------------------------------------------------------
  // Connect to MySQL
 
  $db_handle = mysqli_connect($database_host, $username, $pswd) ;
 
  /* check connection */
  if (mysqli_connect_errno()) {
    printf("Connect server failed: %s\n", mysqli_connect_error());
    exit();
  }
 
  // -- -----------------------------------------------------------
  // Connect to a database
 
  mysqli_select_db($db_handle, "dbviablitz") ;          // HARD CODED MADE NO DIFFERENCE
 
 
  /* check connection */
  if (mysqli_connect_errno()) {
    printf("Connecting to database ".$database_name." failed: %s\n", mysqli_connect_error());
    exit();
  }
 
 
 
  // Prepare FORM
 
  if ($invis_task == "CreateTables")
  {
    echo '<form action="CreateSomeTables.php" method="post">' ;
  } else
  {
    echo '<form action="BackupSomeTables.php" method="post">' ;
  }
 
   
  // ==========================================
  // Show ...

  // THIS IS WHERE IT IS PULLING DATA FROM SOMEWHERE IN IMAGINARY LAND

      $array_result = mysqli_query($db_handle, "SELECT table_name from table_names where seqno > 0 order by seqno ;");
 
  if (mysqli_connect_errno()) {
    printf("SELECT from Table table_name failed. %s\n", mysqli_error($db_handle));
    exit();
  }

  $nrows = mysqli_num_rows($array_result) ;
 
  for ($x = 1;$x<=$nrows; $x++)
  {
        $row = mysqli_fetch_array($array_result, MYSQLI_BOTH);
        
            $tablename= $row["table_name"];
            //$filename='AdminFiles/CreateTableTextFiles/tbl_'.$row["table_name"].'.txt' ;
            $filename='AdminFiles/CreateTableTextFiles/tbl_'.$tablename.'.txt' ;

// I PUT AN echo IN HERE AND IT DOES SHOW UP.
            echo '<input type="checkbox" name="tablenames[]" value="'.$tablename.'">'.$tablename.'<br>' ;
        
  }
1.png
2.png
3.png
4.png
5.png
0
Comment
Question by:Ralph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 78

Accepted Solution

by:
arnold earned 450 total points
ID: 40490514
Echo print, the commands.

You are using database_host variable which does not seem to be defined.

Does your local system where this is run different from the database_host to which it should be connecting?
I.e. You think you are connecting to host1, while the non-definition of the database_host is not define and thus the script connects to the local host.

Try including a show databases directive and gave it displayed. With this information you can see whether you are getting data from the wrong host.

In the circumstances it is impossible to even guesstimate where your data is coming from.

The point deals with confirming the host to which you think you are connecting is actually the host from which the data is retrieved.
0
 
LVL 78

Assisted Solution

by:arnold
arnold earned 450 total points
ID: 40490518
Check the other databases to see whether these tables exist there?
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 50 total points
ID: 40490604
double-check you are really using THAT script, and that you are connecting to the same host in that script than the one you are using phpmyadmin
0
 
LVL 78

Expert Comment

by:arnold
ID: 40490610
note further, that you are defining the username twice as well as the database.

The last databasename you use is blitz1
0
 

Author Comment

by:Ralph
ID: 40495509
Yes, that was the problem.
In one PHP file I had (earlier, thought it was done) not uncommented the necessary line.
No mysterious data now.
Kinda darn.  One less mystery in the world.

Thanks all!
Ralph
0

Featured Post

Webinar: MariaDB® Server 10.2: The Complete Guide

Join Percona’s Chief Evangelist, Colin Charles as he presents MariaDB Server 10.2: The Complete Guide on Tuesday, June 27, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 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