WordPress tells me that I have an syntax error on Description:
[30-Jul-2019 16:50:51 UTC] WordPress-Datenbank-Fehler You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''\do_action, WP_Hook->apply_filters, activate_shn_product, require_once('/plugins/shn-product/includes/class-shn-product-activator.php'), Shn_Product_Activator->__construct, Shn_Product_Activator->shn_store_products, dbDelta
I already tried it with mysqli_real_escape
but it doesn't change anything.
{
"id": 47,
"name": "Brutal Anadrol 90caps",
"purchasePrice": "",
"price": "",
"specialPercent": "0.00",
"specialPercentFMS": "0.00",
"pricePercentSHNStudio": "36.07",
"pricePercentSHNDealer": "15.28",
"franchisePercent": "4.50",
"depositPrice": "0.00",
"status": true,
"statusFMS": true,
"statusSHN": true,
"hasGermanLabel": true,
"needsLabel": true,
"stockIsEditableByShopManager": false,
"fsk18": true,
"taxClass": 2,
"description": "\u003Cp style=\u0022text-align: justify;\u0022\u003EEin gro\u00dfartiger TST-Booster ist der
Aufgabe gewachsen. Er funktioniert, wie erwartet, innerhalb der
erlaubten Grenzen der Herstellung von Nahrungsmittelerg\u00e4nzungen. Es gibt
nur ein Problem: die Ber\u00fccksichtigung von Regeln und Standards, denen
andere folgen.\u003C\/p\u003E
\u003Cp style=\u0022text-align: justify;\u0022\u003EBrutal Anadrol ist anders. Beim
Zusammenstellen haben wir nicht an Legalit\u00e4t gedacht, sondern an
Effektivit\u00e4t und haben deshalb etwas kreiert, was so ist wie nichts
anderes je zuvor.\u003C\/p\u003E
\u003Cp style=\u0022text-align: justify;\u0022\u003ESei kein Mitl\u00e4ufer.\u003C\/p\u003E
\u003Cp style=\u0022text-align: justify;\u0022\u003EVerwende Brutal Anadrol, bevor es verboten wird!\u003C\/p\u003E\u003Ch3\u003E\u003Cspan style=\u0022font-size: 18px;\u0022\u003EZutaten\u003C\/span\u003E\u003C\/h3\u003E
\t\t\u003Cp\u003ETribulus terrestris-Frucht-Extrakt 19,1%, CreaBASE (gepufferte
Kreatin-Monohydrat) 19,1%, Camellia sinensis-Blatt-Extrakt, Kapselh\u00fclle
[Gelatine, gereinigtes Wasser, Farbstoffe (Titandioxid, Brillantblau
FCF, Ponceau 4R*)], Arginin Hydrochlorid 12,5%,
Calcium-alpha-Ketoglutarat 11%, Niacin (Nicotinamid), Serenoa
repens-Frucht-Extrakt 1,9%, Silybum marianum-Samen-Extrakt, Panax
ginseng-Wurzel-Extrakt, Lepidium meyenii Pulver, Trennmittel
(Magnesiumstearat, Siliciumdioxid), Bacopa monnieri Pulver, Coenzym Q10.\u003C\/p\u003E\u003Cp\u003E\u003Cbr\u003E\u003C\/p\u003E",
"weight": "0.11",
"width": 62,
"height": 115,
"depth": 62,
"numberOfSales": 308,
"packagingUnit": null,
"restockDate": null,
"createDate": {
"date": "2015-10-17 23:45:25.000000",
"timezone_type": 3,
"timezone": "Europe\/Berlin"
},
"categorieId": 6,
"childProductId": null,
"manufacturerId": 4,
"dosageFormId": 4,
"productVariationId": null
}
And this is the Code which i use for it
foreach ($products as $product){
$description = esc_sql( addslashes($product->description));
$description = str_replace(array("\", "\
", "\\t"), " ", $description);
$sql = "INSERT INTO " . $this->cache_table_name . " (`id`, `name`, `description` , `purchase_price`, `price`, `weight`, `width`, `height`, `depth`)
VALUES
('" .
$product->id . "', '" .
$product->name . "', '" .
$description . "', '" .
$product->purchasePrice . "', '" .
$product->price . "', '" .
$product->weight . "', '" .
$product->width . "', '" .
$product->height . "', '" .
$product->depth . "');";
dbDelta($sql);
}
This is my Code where he is Inserting
1- Are you sure that you can insert data with dbDelta
in Wordpress?
The dbDelta function looks at the current table structure, compares it to the desired table structure passed to the function, and either adds or modifies the table. It is often used in plugins to create (if the table doesn't exist) or update the table structure. Read more about creating tables in WordPress here: http://codex.wordpress.org/Creating_Tables_with_Plugins.
In order for the function to work correctly, the SQL statement must use the following criteria:
1. You have to put each field on its own line in your SQL statement.
2. You have to have two spaces between the words PRIMARY KEY and the definition of your primary key.
3. You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY.
Also, you must include upgrade.php
before dbDelta()
;
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
dbDelta($sql);
2- Usually, I insert data to MySql with below code.
$wpdb->insert(
$table_name,
array(
...
...
...
)
);