admin管理员组文章数量:1432007
I have these
$wpdb->suppress_errors(false);
$wpdb->show_errors (true);
$wpdbp = $wpdb->prepare($preparedQuery->query, $preparedQuery->values);
$result = $wpdb->get_var($wpdbp);
I further thought of something like this (may be temporary)
if($result === null) {
$error = $wpdb->print_error();
var_dump($error);
}
I read in get_var()
documentation:
Returns: Database query result (as string), or null on failure
My problem here is that $result
is always null when inserting, even if insert succeeds.
How to actually know it there were errors or not?
I expect there may be some other types of get_
methods?
Maybe I sould add something like "SELECT 1;" but even if that works I don't like it much.
I have these
$wpdb->suppress_errors(false);
$wpdb->show_errors (true);
$wpdbp = $wpdb->prepare($preparedQuery->query, $preparedQuery->values);
$result = $wpdb->get_var($wpdbp);
I further thought of something like this (may be temporary)
if($result === null) {
$error = $wpdb->print_error();
var_dump($error);
}
I read in get_var()
documentation:
Returns: Database query result (as string), or null on failure
My problem here is that $result
is always null when inserting, even if insert succeeds.
How to actually know it there were errors or not?
I expect there may be some other types of get_
methods?
Maybe I sould add something like "SELECT 1;" but even if that works I don't like it much.
Share Improve this question asked Apr 18, 2019 at 8:12 TTTTTT 3291 gold badge4 silver badges17 bronze badges1 Answer
Reset to default 1To insert data you should use query()
(documentation), get_var()
method is for selecting data. If error is encountered, query()
returns FALSE.
query()
This function returns an integer value indicating the number of rows affected/selected for SELECT, INSERT, DELETE, UPDATE, etc.
For CREATE, ALTER, TRUNCATE and DROP SQL statements, (which affect whole tables instead of specific rows) this function returns TRUE on success. If a MySQL error is encountered, the function will return FALSE.
$result = $wpdb->query( 'insert query' );
if ( $result === FALSE ) {
// display error
}
本文标签: mysqlHow to get INSERT errors from wpdb
版权声明:本文标题:mysql - How to get INSERT errors from $wpdb? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745576990a2664391.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论