我试图将一些包含连字符和撇号的字符串作为值插入MySQL表中。我指定字符串值:
$venue_name = addslashes(get_the_title($id));
当我回显该值时,我得到:
4B’s Brewery
以及
Ace Hardware - Bailey
我的SQL语句如下所示:
INSERT INTO wp_w2bw2c_venue (id, market_id, venue_status, venue_name,
website, address_1, address_2, city, state, postal_code, phone, fax, email,
logo_attachment_id, featured_image_attachment_id, tagline, description,
doors_open, capacity, venue_type_id, salesperson_id, landing_page_id) VALUES
(817, 7, \'Active\', \'4B’s Brewery\', \'http://4bsbrewery.com/\', \'215 W Main St\',
\'\', \'Cedaredge\', \'Colorado\', \'81413\', \'970-856-7762\', \'\', \'\', 0, 0, \'\', \'\', \'\',
0, \'168\', 89, 0)
INSERT INTO wp_w2bw2c_venue (id, market_id, venue_status, venue_name,
website, address_1, address_2, city, state, postal_code, phone, fax, email,
logo_attachment_id, featured_image_attachment_id, tagline, description,
doors_open, capacity, venue_type_id, salesperson_id, landing_page_id) VALUES
(915, 7, \'Active\', \'Ace Hardware – Bailey\', \'\', \'Moore Lumber & Hardware\', \'\',
\'Bailey\', \'Colorado\', \'\', \'720-924-3999\', \'\', \'\', 0, 0, \'\', \'\', \'\', 0, \'168\',
89, 0)
我正在使用
dbDelta($sql);
更新数据库。
但我遇到如下数据库错误:
WordPress database error: [You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right syntax
to use near \'\'4B’\' at line 4]
INSERT INTO wp_w2bw2c_venue (id, market_id, venue_status, venue_name,
website, address_1, address_2, city, state, postal_code, phone, fax, email,
logo_attachment_id, featured_image_attachment_id, tagline, description,
doors_open, capacity, venue_type_id, salesperson_id, landing_page_id) VALUES
(817, 7, \'Active\', \'4B’
WordPress database error: [You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right syntax to
use near \'\'Ace Hardware –\' at line 4]
INSERT INTO wp_w2bw2c_venue (id, market_id, venue_status, venue_name,
website, address_1, address_2, city, state, postal_code, phone, fax, email,
logo_attachment_id, featured_image_attachment_id, tagline, description,
doors_open, capacity, venue_type_id, salesperson_id, landing_page_id) VALUES
(915, 7, \'Active\', \'Ace Hardware –
特殊字符的和-终止字符串。我尝试了addslashes()、str\\u replace(“-”、“-”、$venue\\u name)和mysql\\u real\\u escape\\u string(),但没有成功。如何准备字符串以接受为mysql VARCHAR表列值?