I am trying to create a view in a MySQL database that has the same name as a view in another database using this line of code in php.
mysql_query('CREATE VIEW `' . $targetDB . '`.`' . $row[0] . '` LIKE `' . $sourceDB . '`.`' . $row[0] . '`') or die(mysql_error());
However when I run my code I get this error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE copyinrdb
.abnormal_limit_view
' at line 1
What am I doing wrong my full code is if it helps:
<?php
set_time_limit(0);
function duplicateTables($sourceDB=NULL, $targetDB=NULL) {
$link = mysql_connect('my_host', 'my_user', 'my_pass') or die(mysql_error()); // connect to database
$results = mysql_query('SHOW FULL TABLES FROM copyinrdb WHERE TABLE_TYPE= "VIEW"') or die(mysql_error());
while($row = mysql_fetch_row($results)) {
mysql_query('CREATE VIEW `' . $targetDB . '`.`' . $row[0] . '` LIKE `' . $sourceDB . '`.`' . $row[0] . '`') or die(mysql_error());
mysql_query('INSERT INTO `' . $targetDB . '`.`' . $row[0] . '` SELECT * FROM `' . $sourceDB . '`.`' . $row[0] . '`') or die(mysql_error());
}
mysql_free_result($results);
mysql_close($link);
} // end duplicateTables()
duplicateTables('copyinrdb', 'copytest1');
?>