这是我收到错误的示例代码,当尝试在远程服务器上运行代码返回错误时,它在localhost中运行良好,建议我在代码中有任何其他方法来实现相同的功能。
<?php
if (!$con = mysql_connect('localhost', 'root', 'password')) {
die('An error occurred while connecting to the MySQL server!<br><br>' . mysql_error());
}
if (!mysql_select_db(sample)) {
die('An error occurred while connecting to the database!<br><br>' . mysql_error());
}
$sql = array(
'DROP TABLE IF EXISTS content;',
'CREATE TABLE content SELECT * FROM sample2.content'
);
if (sizeof($sql) > 0) {
foreach ($sql as $query) {
if (!mysql_query($query)) {
die('A MySQL error has occurred!<br><br>' . mysql_error());
}
}
}
mysql_close($con);
?>