Solved

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

Posted on 2014-12-09
5
247 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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