That doesn't really make sense. Drupal is just a PHP application; if you're using exactly the same connection details in Drupal as you are in your stand-alone PHP application, and that works, it's only logical that your Drupal connection will work too.
You've obviously checked that the username and password are correct, but have you checked the Drupal is connecting to the server from
localhost? That would be the only other possible difference. If Drupal is connecting from a remote machine then you'll need to grant specific privileges to the user for that specific location.
The easiest way to see what you've already got is to run a
SHOW GRANTS query on the database in question. That will show you something like this:
Grants for username@localhost
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'username'@'localhost' IDENTIFIED BY PASSWORD '*xxxxxxxxxxxxx'
Plus a few more more rows more than likely.
Check through those rows to make doubly sure that there is a grant for
INSERT for the database user AND the location that the Drupal website is connecting from.
You could maybe get around the error using
$record = new stdClass;
$record->col1 = 'something';
$record->col2 = 'something';
$record->col3 = 'something';
But that really shouldn't make any difference