gpt4 book ai didi

php - 使用php和mysql创建csv文件时有文件大小限制吗?

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

我正在尝试创建 csv 文件来更新 Magento 中的库存。我的代码如下:

    <?php
require_once ('../db.php');

$conn = db_connect();
$inventory = array();
$csvContent = "";
$n=0;


$result = $conn->query("select inventory.sku, book.author, book.title,
book.publisher, book.pub_date, book.edition,
inventory.isbn13, book.binding, book_condition.book_condition, defect.defect, note,
feature, inventory.ourPrice, inventory.cost, inventory.quantity, subtitle, weight
from inventory
LEFT JOIN book on book.isbn13 = inventory.isbn13
LEFT JOIN defect on inventory.defect_id = defect.defect_id
LEFT JOIN note on inventory.note_id = note.note_id
LEFT JOIN feature on inventory.feature_id = feature.feature_id
LEFT JOIN book_condition on book_condition.condition_id = defect.condition_id
where inventory.quantity >0");

$num_rows = $result->num_rows;

if($num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$inventory[$n] = array('sku' => $row['sku'],
'author' => $row['author'],
/*'title' => $row['title'],
'publisher' => $row['publisher'],
'pub_date' => $row['pub_date'],
'edition' => $row['edition'],
'publisher' => $row['publisher'],
//'isbn10' => $isbn10,
'isbn13' => $row['isbn13'],
'binding' => $row['binding'],
'condition' => $row['condition'],
'defects' => $row['defect'],
'notes' => $row['note'],
'feature' => $row['feature'],
'price' => number_format($row['ourPrice'], 2, '.', ''),
'cost' => $row['cost'],
'description' => $row['defect'],
'quantity' => $row['quantity'],
'store' => "default",
'websites' => "base",
'attribute_set' => "books",
'type' => "simple",
'category' => "6",
'type' => "simple",
'image' => "/bcpics/".$row['isbn13'].".gif",
'small_image' => "/bcpics/".$row['isbn13'].".gif",
'thumbnail' => "/bcpics/".$row['isbn13'].".gif",
'page_layout' => "No Layout updates",
'options_container' => "Block after Info Column",
'weight' => $row['weight'],
'status' =>"Enables",
'tax_class_id' =>"Taxable Goods",
'visibility' =>"Catalog, Search",
'enable_googlecheckout' =>"yes",
'is_recurring' =>"no",
'min_qty' =>"0",*/
'use_config_min_qty' =>"1",
'is_qty_decimal' =>"0",
'backorders' =>"0",
'use_config_backorders' =>"1",
'min_sale_qty' =>"1",
'use_config_min_sale_qty' =>"1",
'max_sale_qty' =>"0",
'use_config_max_sale_qty' =>"1",
'is_in_stock' =>"1",
'use_config_notify_stock_qty' =>"1",
'manage_stock' =>"0",
'use_config_manage_stock' =>"1",
'stock_status_changed_automatically' =>"0",
'use_config_qty_increments' =>"1",
'qty_increments' =>"0",
'use_config_enable_qty_increments' =>"1",
'enable_qty_increments' =>"0",
'store_id' =>"1",
'product_type_id' =>"simple",
'add_delete' => "",
'url_key' => "",
'gift_message_available' => "",
'Topic' => "",
'Subtitle'=> $row['subtitle'],
'meta_title' => "",
'meta_description' => "",
'custom_design' => "",
'url_path' => "",
'special_price' => "",
'meta_keyword' => "",
'custom_layout_update' => "",
'news_from_date' => "",
'news_to_date' => "",
'special_from_date' => "",
'special_to_date' => "",
'custom_design_from' => "",
'custom_design_to' => "",
'low_stock_date' => "",
'notify_stock_qty' => "",
'product_status_changed' => "",
'product_changed_websites'=> "",
'has_options'=> "0"

);
//print_r($inventory);die;
$n++;
} //end of while loop
} // end of if statement

$csvInventory = to_csv($inventory);

function to_csv( $array ) {
$csv = "";

if (count($array) == 0) return "No SKU's found";

## Grab the first element to build the header
$arr = array_pop( $array );
$temp = array();
foreach( $arr as $key => $data ) {
$temp[] = $key;
}
$csv = implode( ',', $temp ) . "\r\n";

## Add the data from the first element
$csv .= to_csv_line( $arr );

## Add the data for the rest
foreach( $array as $arr ) {
$csv .= to_csv_line( $arr );
}

return $csv;
}

function to_csv_line( $array ) {
$temp = array();
foreach( $array as $elt ) {
$temp[] = '"' . addslashes( $elt ) . '"';
}

$string = implode( ',', $temp ) . "\r\n";

return $string;
}

$conn->close();

$myFile = "/home/bookcell/public_html/testbcos/web/inv/BCWebsite" . date("mdY") . ".csv";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $csvInventory;
fwrite($fh, $stringData);
fclose($fh);

我的问题是,如果我尝试使用 $inventory[$n] = array() 中的所有参数,我将无法使其工作。我可以让数组中除大约 30 行之外的所有行同时工作,目前 /**/ 中的所有内容都将不起作用。我尝试过更改 /**/ 之间的字段,所以我知道每一行都会毫无问题地进入 csv。我检查了服务器上的错误日志,没有错误,传输日志显示它应该可以工作。有人看到我哪里出错了吗?有没有更好的方法来获得我需要的结果?

最佳答案

我已经从 PHP 和 MySQL 导出了 600MB 以上大小的 csv 文件,方式与您类似,没有任何问题。听起来像是您的环境设置问题 - 与代码或技术限制无关。

关于php - 使用php和mysql创建csv文件时有文件大小限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11249850/

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