Solved

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

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

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 76

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 76

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

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

16 Experts available now in Live!

Get 1:1 Help Now