Pages

Friday, March 27, 2020

Get CREATE TABLE for all tables using CodeIgniter


I have an app on my phone that I use as a pocket reference when I need field names, relationships in GroceryCrud. It has an Import from SQL feature.
I ran my code. Copied the output to keep.google.com and from there pasted the SQL in the mobile app.
This was a quick thing I needed so I just placed it in a controller.
Code follows:

 
public function tableSQLCreate() {
  try {
   $pdo = $this->db;

  }
  catch(PDOException $e) {
   die("Could not connect to the database\n");
  }



  echo '<#pre>';
  try{
   $stmt1 = $pdo->query('SHOW TABLES' );
    try {
     foreach($stmt1->result() as $result) {

       foreach ($result as $key => $value) {
        $stmt2 = $pdo->query("SHOW CREATE TABLE `". $value ."`" );
        $table = $stmt2->result();
        foreach ($table[0] as $key => $value) {
         if ($key=="Create Table") {
         echo "$value;\n\n";
         }
        }
       }

     }
    } catch(PDOException $e) {
      die("Could not get result nested");
    }


  }
  catch(PDOException $e) {
   die("Could not get result");
  }
  
  echo '<#/pre>';

 }
Be sure to remove the # symbol from the pre tags. It was a dirty way around the Blogger formatter.


It outputs

CREATE TABLE `login_attempts` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `ip_address` varchar(15) NOT NULL,
  `login` varchar(100) NOT NULL,
  `time` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Friday, August 17, 2018

Connect a wireless printer without WPS or USB

I just finished setting up DD WRT on my wireless router. Firestick conected to my new WLAN. Now I wanted to connect my HP Deskjet 3520 to my WLAN and the only way I could connect to the router seems WPS but that is not working on the router even though it has the button.
Anyhow. I know that this printer model has a web interface so I connected via WiFi Direct. Then I found my IP address on my mobile device. My IP was 192.168.179.200. Opened up the browser and went to 192.168.179.1 to access the printer's server. There it has a nice interface to connect to the wireless network of choice.

The settings from this point will depend on your particular setup.


Recap.
Connect via Wi-Fi direct.
Open the app that your printer works with. The one you use for sending print jobs to it.
That app will tell you the printer's IP address.
Navigate to that address
Find the wireless setup wizard and configure your settings accordingly.