Php 调用mysql\u insert\u id()在drupal中不起作用
我正在从drupal向moodle数据库中插入一行,并希望获得最后插入行的id,但我什么也没有得到。 这是我的密码Php 调用mysql\u insert\u id()在drupal中不起作用,php,mysql,drupal-7,Php,Mysql,Drupal 7,我正在从drupal向moodle数据库中插入一行,并希望获得最后插入行的id,但我什么也没有得到。 这是我的密码 $moodle_database = array( 'database' => 'moood', 'username' => 'root', 'password' => '',
$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();
如果您使用Drupal 6,则应使用以下代码:
db_last_insert_id('mdl_question', 'your_primary_key_id');
如果使用Drupal 7,请参阅以下链接:
http://drupal.stackexchange.com/questions/58991/how-to-retrieve-last-mysql-insert-id-from-drupal-7-db-merge
如果您使用Drupal 6,则应使用以下代码:
db_last_insert_id('mdl_question', 'your_primary_key_id');
如果使用Drupal 7,请参阅以下链接:
http://drupal.stackexchange.com/questions/58991/how-to-retrieve-last-mysql-insert-id-from-drupal-7-db-merge
在drupal 6中,使用
db_last_insert_id()代码>
在Drupal7InsertQuery::execute()
返回最后一个插入id。在Drupal6中,使用db\u最后一个插入id()代码>
在Drupal 7InsertQuery::execute()
中返回最后一个插入id。请访问此urlhttps://www.drupal.org/node/151718
,可能会对您有所帮助。请访问此urlhttps://www.drupal.org/node/151718
,可能会对您有所帮助。它无法将其识别为函数您正在使用的drupal版本。调用未定义函数db_last_insert_id()这是我使用drupal 7时得到的响应。它无法将其识别为函数您正在使用的drupal版本。调用未定义函数db_last_insert_id()这是我使用drupal 7得到的响应。我应该在InsertQuery$id=db_insert('mytable')->字段(数组('field1'=>'value'))->执行()中编写插入查询吗;我应该在InsertQuery$id=db_insert('mytable')->fields(数组('field1'=>'value'))->execute()中编写插入查询吗;