0

完全迷失了。基本上,该脚本在 mysql 中创建表并用假期填充它们。

$link = mysqli_connect("127.0.0.1", "root", "root", "wolla");
if ( !$link ) {
    die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
}

$createTablesQuery1 = "SET foreign_key_checks = 0;";
$createTablesQuery2 = "DROP TABLE IF EXISTS `calendarCountries`;";
$createTablesQuery3 = "CREATE TABLE `calendarCountries` ( `id` int(5) NOT NULL AUTO_INCREMENT, `country` varchar(50) NOT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET = latin1;";
$createTablesQuery4 = "insert into calendarCountries (id,country) values (1,'US');";
$createTablesQuery5 = "DROP TABLE IF EXISTS `calendarWorldHolidays`;";
$createTablesQuery6 = "CREATE TABLE `calendarWorldHolidays` (`holidayName` varchar(150) NOT NULL,`holidayDate` date NOT NULL,`countryCode` int(5) DEFAULT NULL,KEY `countryCode` (`countryCode`),CONSTRAINT `calendarWorldHolidays_ibfk_1` FOREIGN KEY (`countryCode`) REFERENCES `calendarCountries` (`id`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET = latin1;";
$createTablesQuery7 = "SET foreign_key_checks = 1;";

if ( !mysqli_multi_query( $link, $createTablesQuery1.$createTablesQuery2.$createTablesQuery3.$createTablesQuery4.$createTablesQuery5.$createTablesQuery6.$createTablesQuery7 ) )
    die( mysqli_error( $link ).'<br>');
    mysqli_close( $link );

    //INSERT HOLIDAYS INTO calendarWorldHolidays
    $link = mysqli_connect("127.0.0.1", "root", "root", "wolla");
    mysqli_query( $link, "SET foreign_key_checks = 0;");
    $count = 0;
    $holidayCount = count( $holidayNames );
    while ( $count < $holidayCount ) {
        $insertHolidayQuery = 'Insert into calendarWorldHolidays (holidayName, holidayDate, countryCode) values ("'.$holidayNames[$count].'", '.$holidayDates[$count].'", 1)';
        if ( !mysqli_query( $link, $insertHolidayQuery ) ) {
        die(mysqli_error($link).'<br>');
        } else {
        $count++;
        }
    }
    mysqli_query( $link, "SET foreign_key_checks = 1;");

脚本表格很好;但是,当我尝试在 while 循环中插入时,出现以下错误

表 'wolla.calendarworldholidays' 不存在
但是该表确实存在,因为创建它的代码执行得很好,当我检查时,我可以在 SQLPRO 和 phpmyadmin 中看到它

$holidayNames是一个字符串数组$holidayDates是一个日期数组

而这两者都有内在的价值

请帮助,对此事的任何建议表示赞赏。

4

1 回答 1

0

撤消的解决方案出现语法错误的原因是

Insert into

应该

INSERT INTO

全部大写

于 2013-10-14T06:34:44.457 回答