Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 调用mysql\u insert\u id()在drupal中不起作用_Php_Mysql_Drupal 7 - Fatal编程技术网

Php 调用mysql\u insert\u id()在drupal中不起作用

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' => '',

我正在从drupal向moodle数据库中插入一行,并希望获得最后插入行的id,但我什么也没有得到。 这是我的密码

                $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()


在Drupal7
InsertQuery::execute()
返回最后一个插入id。

在Drupal6中,使用
db\u最后一个插入id()


在Drupal 7
InsertQuery::execute()
中返回最后一个插入id。

请访问此url
https://www.drupal.org/node/151718
,可能会对您有所帮助。请访问此url
https://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()中编写插入查询吗;