admin管理员组文章数量:1290317
I know this type of question has been asked over and over, but I couldn't find a solution for my problem, so I hope you can help me. I am using WP 3.3. and I have created a custom table. Now I want to insert some data into it, but I can't get it working. This is my code:
global $wpdb;
$table_name = $wpdb->prefix . "my_data";
$wpdb->insert($table_name, array(
'my_id' => NULL,
'my_day' => $day,
'my_month' => $month,
'my_abbr' => $abbr,
'my_venue' => $venue,
'my_geo' => $geo_one.", ".$geo_two,
'my_artist' => $artist,
'my_link' => $link
)
);
I am trying to insert data for several hours now without luck. To my eyes the code is correct, but I guess I am just mussing something important here. Any pointers would be appreciated! Thank you
I know this type of question has been asked over and over, but I couldn't find a solution for my problem, so I hope you can help me. I am using WP 3.3. and I have created a custom table. Now I want to insert some data into it, but I can't get it working. This is my code:
global $wpdb;
$table_name = $wpdb->prefix . "my_data";
$wpdb->insert($table_name, array(
'my_id' => NULL,
'my_day' => $day,
'my_month' => $month,
'my_abbr' => $abbr,
'my_venue' => $venue,
'my_geo' => $geo_one.", ".$geo_two,
'my_artist' => $artist,
'my_link' => $link
)
);
I am trying to insert data for several hours now without luck. To my eyes the code is correct, but I guess I am just mussing something important here. Any pointers would be appreciated! Thank you
Share Improve this question asked Dec 26, 2011 at 21:38 SvenSven 951 gold badge2 silver badges5 bronze badges 2 |2 Answers
Reset to default 17When $wpdb
method doesn't perform as it should it is likely issue with resulting SQL query (because of wrong input or something else).
Follow wpdb reference in Codex
for troubleshooting:
- enable database error display via
$wpdb->show_errors()
- check what query is being formed and run via
$wpdb->last_query
The wpdb
-class does not have an insert method. It would be best if you didn't use the query; see the codex, and you don't find this function insert()
- http://codex.wordpress/Class_Reference/wpdb
An example of inserting a custom table on WPDB; use a default CREATE TABLE
-SQL Syntax and create with the query()
of wpdb
the table with your values.
$table = $GLOBALS['wpdb'] -> prefix . 'my_data';
$GLOBALS['wpdb'] -> query(
"CREATE TABLE $table (
called_by varchar(96) NOT NULL,
my_name varchar(96) NOT NULL,
my_type varchar(15) NOT NULL,
first_call int(11) NOT NULL,
arg_count tinyint(4) NOT NULL,
file_name varchar(128) NOT NULL,
line_num smallint NOT NULL,
PRIMARY KEY (first_call, my_name) )"
);
To insert this source, use the register_activation_hook()
-hook; only on activation, the plugin will install the table if it doesn't exist. On register_uninstall_hook()
I delete custom tables.
本文标签: wpdbgtinsert not working in any way
版权声明:本文标题:$wpdb->insert not working in any way 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741498357a2381938.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$wpdb->print_error();
in the next line to insert and check if it throws any errors. – tamilsweet Commented Dec 27, 2011 at 5:07