title: PHP / MySQL - Create Table If Not Exist
body: <p>I have 2 db connections, db1 is the main db and db2 is the copy from.</p>
  
  <p>my script is copying from db2 (has this was the development) to make db1 the same.</p>
  
  <p>However i cannot get the create table if not exist to work with using more then 1 database and using "LIKE".</p>
  
  <p>This is the connection:</p>
  
  <pre><code>&lt;?php
  $host = 'localhost';
  
  $db1 = "***";
  $username_db1 = '***';
  $password_db1 = '***';
  $db_c1 = mysql_connect($host, $username_db1, $password_db1) or die('Error connecting to Database!&lt;br&gt;'.mysql_error());
  
  $db2 = "***";
  $username_db2 = '***';
  $password_db2 = '***';
  $db_c2 = mysql_connect($host, $username_db2, $password_db2, true) or die('Error connecting to Database!&lt;br&gt;'.mysql_error());
  
  mysql_select_db($db1, $db_c1);
  mysql_select_db($db2, $db_c2);
  ?&gt;
  </code></pre>
  
  <p>This is the script well part of it.</p>
  
  <pre><code>$tables1 = array();
  $tables2 = array();
  
  $res = mysql_list_tables($db1, $db_c1);
  while (list($tmp) = mysql_fetch_row($res))
  {
      $tables1[] = $tmp;
  }
  
  $res = mysql_list_tables($db2, $db_c2);
  while (list($tmp) = mysql_fetch_row($res))
  {
      $tables2[] = $tmp;
  }
  
  // Tables creates if not exists
  foreach($tables2 as $k=&gt;$v)
  {
      mysql_query("CREATE TABLE IF NOT EXISTS ".$db1.".".$v." LIKE ".$db2.".".$v, $db_c1);
  }
  </code></pre>
  
  <p>I think the problem is with the LIKE i dont think it is reading it correctly, i have var dumped $tables2 and it does come up with the results.</p>
  
  <p>Thanks </p>