gpt4 book ai didi

PHP/Mysql - 加载文件和查询记录

转载 作者:行者123 更新时间:2023-11-29 19:33:41 24 4
gpt4 key购买 nike

在这里尝试了一些事情,但不知怎的,我似乎无法通过 PHP 取回我的记录来执行后续操作。本质上,我将记录加载到临时表(WORKS)中,调用过程然后将它们迁移到我的实时表(WORKS),然后我需要简单地循环导入的每条记录以生成图像。如果我回显查询并通过 Workbench 运行它,我会取回数据,但不知何故在 PHP 中查询没有返回任何内容,我错过了什么?

public function import_members() {
$this->filepath=htmlspecialchars(strip_tags($this->filepath));

$status = "success";
$msg = "";

$query = "LOAD DATA LOCAL INFILE '" . $this->filepath ."' INTO TABLE temp_imported
CHARACTER SET 'latin1'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\\n'
IGNORE 1 LINES
(fname,lname,email,phone,address,city,province,postal,dob,member_no)";

echo $query . "<br><br>";

// EXECUTE LOAD - ON SUCCESS
if ($this->conn->query($query)) {
try {
// CALL PROC TO IMPORT DATA INTO LIB_MEMBERS
$stmt = $this->conn->query("CALL sp_import_members(@rowcount)");

while ($row = mysqli_fetch_array($stmt)) {
$records = $row[0];
}

mysqli_free_result($stmt);
$msg = "File was imported successfully! <br> A total of " . $records . " records were imported from your file" ;
}
catch (Exception $ex) {
$msg = $ex ;
$status = 'danger';
}

echo $status . "<br><br>";

if ($status == "success"){
// GENERATE BARCODE IMAGES FOR IMPORTED
$querybar = "Select barcode from lib_members where barcode is not null and DATE(datein) = date(now())";
echo $querybar . "<br><br>";

$stmt2 = $this->conn->query($querybar);
$rownum = $stmt2->num_rows;

if ($rownum){
echo $rownum;
}
else {
echo "NO";
}
}
}
else {
$msg = "There was a problem importing your file";
}

echo "<div style='width:40%; margin:0 auto; text-align:center; font-size:12px;' class='alert alert-". $status ."' role='alert'>" . $msg . "</div>";
}
}

我的输出当前显示:

LOAD DATA LOCAL INFILE '/Users/DB/Sites/Scan_MASTER/imported/members.csv' INTO TABLE temp_imported CHARACTER SET 'latin1' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (fname,lname,email,phone,address,city,province,postal,dob,member_no)

success

Select barcode from lib_members where barcode is not null and DATE(datein) = date(now())

Notice: Trying to get property of non-object in /Users/db/Sites/Scan_MASTER/_members.php on line 590

NO

第 590 行由我的“num_rows”行组成

最佳答案

尝试commit行后$this->conn->query($query)

关于PHP/Mysql - 加载文件和查询记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41650620/

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