Solved

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

Posted on 2014-12-09
5
242 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
  • 3
5 Comments
 
LVL 77

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 77

Assisted Solution

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

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 77

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
understanding output of mysql version 2 60
showing numeric numbers 2 36
Insert data into database 2 42
How to update the value of duplicated records (except latest one) 2 18
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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