Solved

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

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a Select Query and Populate a Table 3 51
AWS EC2 & RDS Instance 5 50
how to access a remote mysql database with xampp 3 24
MySql Recovery 2 27
Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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