我在drupal的moodle數據庫中插入一行,並想獲取最後一個插入行的id,但我無處可去。 這是我的代碼。調用mysql_insert_id()在drupal中不工作
$moodle_database = array(
'database' => 'moood',
'username' => 'root',
'password' => '',
'host' => 'localhost', //52.23.83.176
'driver' => 'mysql',
);
Database::addConnectionInfo('moodle_db', 'default', $moodle_database);
db_set_active('moodle_db');
try {
$question_query ="INSERT INTO mdl_question ".
"(category,parent,name,questiontext,generalfeedback) ".
"VALUES ".
"('$category','$parent','$name','$questiontext','$generalfeedback')";
$queryResult=db_query($question_query);
$id = mysql_insert_id($queryResult);
}
catch (Exception $e) {
drupal_set_message(t('Exception while fetching question data ' . $e->getMessage()));
}
db_set_active();
請訪問這個URL'https:// www.drupal.org/node/151718',可以幫助你。 –