How to use wordpress wpdb class to insert data

admin

Administrator
Staff member
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
Code:
insert.php
then i added following code

Code:
<?php       
global $wpdb;
$wpdb->insert($wpdb->album , array("ID"=>1, "Name"=>'something'), array("%d", "%s"));

 ?>

but it give this error
Code:
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.