ich will dasten von einen file in die oscommerce products tabelle füllen
aber das insert klappt nicht und ich finde denm fehler nicht.
das schema:
erster versich keine fehlermeldung aber nix wird gepeichert:
2ter versuch bekomm Error, insert query failed
aber das insert klappt nicht und ich finde denm fehler nicht.
das schema:
name typ null erlaubt
products_id int(11) Nein auto_increment
products_quantity int(4) Nein
products_model varchar(12) Ja NULL
products_image varchar(64) Ja NULL
products_price decimal(15,4) Nein
products_date_added datetime Nein
products_last_modified datetime Ja NULL
products_date_available datetime Ja NULL
products_weight decimal(5,2) Nein
products_status tinyint(1) Nein
products_tax_class_id int(11) Nein
manufacturers_id int(11) Ja NULL
products_ordered int(11)
products_id int(11) Nein auto_increment
products_quantity int(4) Nein
products_model varchar(12) Ja NULL
products_image varchar(64) Ja NULL
products_price decimal(15,4) Nein
products_date_added datetime Nein
products_last_modified datetime Ja NULL
products_date_available datetime Ja NULL
products_weight decimal(5,2) Nein
products_status tinyint(1) Nein
products_tax_class_id int(11) Nein
manufacturers_id int(11) Ja NULL
products_ordered int(11)
erster versich keine fehlermeldung aber nix wird gepeichert:
Code:
<?php
include 'vars.php';
echo "connecting to ".$db_host."<br> ".$db_user."<br>".$db_password."<br>".$db_name."<br>";
$dbObj = new mysqli($db_host, $db_user, $db_password,$db_name);
$row = 1;
$handle = fopen ("data.csv","r");
while ( ($data = fgetcsv ($handle, 1000, ";")) !== FALSE ) {
$num = count ($data);
print "<p> $num fields in line $row: <br>\n";
If ($row<=1){
print $data[0] . "<br>\n";
print_r($data);
$stmt = mysqli_stmt_init($dbObj);
$sql = "INSERT INTO products (products_id ,products_quantity ,products_image ,products_price,
products_date_added, products_weight, products_status,products_tax_class_id )
VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
echo "foo <br>";
if ($stmt = $dbObj->prepare($sql)) {
if (!$stmt) {
die( $db->error);
} echo "foo <br>";
$stmt->bind_param("iisisii", $row, 1, $data[4],$data[3], date('Y-m-d H:i:s', $unix_timestamp), 1, 1 );
$stmt->execute();
if (!$stmt->execute()) {
die( $stmt->error);
}
$stmt->close();
$dbObj->close();
}
}
$row++;
}
fclose ($handle);
?>
Code:
<?php
include 'vars.php';
echo date('Y-m-d H:i:s', $unix_timestamp);
echo "connecting to ".$db_host."<br> ".$db_user."<br>".$db_password."<br>".$db_name."<br>";
$con = mysql_connect($db_host, $db_user, $db_password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$row = 1;
$handle = fopen ("data.csv","r");
while ( ($data = fgetcsv ($handle, 1000, ";")) !== FALSE ) {
$num = count ($data);
print "<p> $num fields in line $row: <br>\n";
If ($row<=1){
print $data[0] . "<br>\n";
print_r($data);
mysql_select_db("osc", $con);
mysql_query("INSERT INTO products (products_id ,products_quantity ,products_image ,products_price, products_date_added,
products_weight, products_status, products_tax_class_id )
VALUES (".$row.", 1, ".$data[4].",".$data[3].", ".date('Y-m-d H:i:s', $unix_timestamp).", 1, 1 );")
or die(mysql_error());
echo "foo <br>";
}
$row++;
}
fclose ($handle);
?>

Kein Mensch scrollt gerne kilometerweit nach rechts.
Comment