I am new to wordpress I am try to create table and insert data to that table. so within the wordpress database I created table called ‘album’ then I created directory called ‘my-codes'(within root directory/ same level with ‘wp-admin’ , ‘wp-content, ‘wp-includes’ directories)
within that directory I created insert.php then i added following code
<?php
global $wpdb;
$wpdb->insert($wpdb->album , array("ID"=>1, "Name"=>'something'), array("%d", "%s"));
?>
but it give this error Fatal error: Call to a member function insert() on a non-object in C:\wamp\www\wordpress\my-codes\insert.php what is the mistake I did, please help me.
You have to load the WordPress files within your script, so that you have access to WordPress’
$wpdbobject:This will load all of WordPress, even the functionality you don’t need. If you want to only load the database part, read this article.
Update – The first argument to the
insertmethod should be the name of your table: