Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Gregory_v87 on
Hello,
I want to use db_insert inside a custom created php file.
With some searching i found that i need to initialize soms files from the include directory.
While trying this, nothing seems to work.
my code from my custom php file.
the path to my boostrap.inc, database.inc and database.mysql.inc are correct.
// include needed files
include('../../../../../includes/bootstrap.inc');
include('../../../../../includes/database.inc');
include('../../../../../includes/database.mysql.inc');
// Launch drupal start: configuration and database bootstrap
conf_init();
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
// Now you can use drupal database with drupal's dbal:
// Unlock user admin if blocked
db_query("UPDATE {users} set status = 1 where uid = 1");
$nid = db_insert('table')
->fields(array(
'numbers' => ('23456')
))
->execute();
drupal_set_message(t('Content was added'));
Hope someone can help me.
Comments
RE: Correct subject: Drupal`s db_insert()
The above code has lots of problem. Below is 100% working solution..
Create a file like somename.php in Drupal Root folder...and run below script.
Cheers !!
awsome! Thx!! :-)
awsome! Thx!! :-)