gpt4 book ai didi

PHPExcel 未插入 MySQL 数据库

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

我正在使用PHPExcel我正在测试将数据从文件上传到 MySQL 中的表的能力。

我提取的数据将始终从单元格 C8 开始,我需要 C、D、E 列中的数据, F 和 G 直到行为空。

现在,下面的代码将提取数据。我能够回显我的所有值,问题似乎出在 $insertTable 查询(或附近),因为数据未插入。

另外 - 我没有收到任何错误

脚本运行完毕后,出现消息“记录已添加”,但是当我查看 phpMyAdmin 中的表格时 - 我什么也没看到。

任何人都可以发现错误吗?另外,如果有人想指导我将其转换为 PDO,我将不胜感激!!

<?php
/************************ YOUR DATABASE CONNECTION START HERE ****************************/

define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "root"); // set database user
define ("DB_PASS",""); // set database password
define ("DB_NAME","setpoints"); // set database name
define ("DSN", "mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=utf8");


$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

$databasetable = "job21433";

/************************ YOUR DATABASE CONNECTION END HERE ****************************/

$jobnum = "21433189-01";

set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
include 'PHPExcel/IOFactory.php';

// This is the file path to be uploaded.
$inputFileName = '21433189_LadnerLiesure_pointsreport.xlsx';

try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}


$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet); // Here get total count of row in that Excel sheet


for($i=8;$i<=$arrayCount;$i++){
$block_name = trim($allDataInSheet[$i]["C"]);
$typ = trim($allDataInSheet[$i]["D"]);
$obj_id = trim($allDataInSheet[$i]["E"]);
$device_id = trim($allDataInSheet[$i]["F"]);
$obj_name = trim($allDataInSheet[$i]["G"]);


$query = "SELECT BLOCK_NAME FROM `job21433` WHERE BLOCK_NAME = '".$block_name."' and TYP = '".$typ."' and OBJ_ID = '".$obj_id."' and DEVICE_ID = '".$device_id."' and OBJ_NAME = '".$obj_name."'";
$sql = mysql_query($query);
$recResult = mysql_fetch_array($sql);
$existName = $recResult["BLOCK_NAME"];

if($existName=="") {
$insertTable= mysql_query("insert into `job21433` (JOBNUM, BLOCK_NAME, TYP, OBJ_ID, DEVICE_ID, OBJ_NAME) values('".$jobnum."', '".$block_name."', ".$typ."', ".$obj_id."', ".$device_id."', ".$obj_name."');");
$msg = 'object name = '.$obj_name.'Record has been added. <div style="Padding:20px 0 0 0;"><a href="">Go Back to tutorial</a></div>';
} else {
$msg = 'Record already exist. <div style="Padding:20px 0 0 0;"><a href="">Go Back to tutorial</a></div>';
}
}
echo "<div style='font: bold 18px arial,verdana;padding: 45px 0 0 500px;'>".$msg."</div>";

?>

数据库的设置方式如下:

enter image description here

最佳答案

, ".$typ."', ".$obj_id."', ".$device_id."', ".$obj_name."' <- 缺少引号?

关于PHPExcel 未插入 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26185778/

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