gpt4 book ai didi

php - 在php中插入新创建的表返回 'Table table_name doesn' t存在'

转载 作者:行者123 更新时间:2023-11-30 01:12:35 24 4
gpt4 key购买 nike

完全迷失了。基本上,该脚本在 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 是日期数组

这两者都有内在的值(value)

请帮忙,我们非常感谢任何有关此事的建议。

最佳答案

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

Insert into

应该是

INSERT INTO

全部大写

关于php - 在php中插入新创建的表返回 'Table table_name doesn' t存在',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19351828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com