/** * Executes the sql query and get the result, then move back to the calling page * * @param array $url_params url parameters array * @param array $query built query from PMA_buildSqlQuery() * * @return array $url_params, $total_affected_rows, $last_messages * $warning_messages, $error_messages, $return_to_sql_query */ function PMA_executeSqlQuery($url_params, $query) { $return_to_sql_query = ''; if (!empty($GLOBALS['sql_query'])) { $url_params['sql_query'] = $GLOBALS['sql_query']; $return_to_sql_query = $GLOBALS['sql_query']; } $GLOBALS['sql_query'] = implode('; ', $query) . ';'; // to ensure that the query is displayed in case of // "insert as new row" and then "insert another new row" $GLOBALS['display_query'] = $GLOBALS['sql_query']; $total_affected_rows = 0; $last_messages = array(); $warning_messages = array(); $error_messages = array(); foreach ($query as $single_query) { if ($_REQUEST['submit_type'] == 'showinsert') { $last_messages[] = PMA_Message::notice(__('Showing SQL query')); continue; } if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) { $result = $GLOBALS['dbi']->tryQuery($single_query); } else { $result = $GLOBALS['dbi']->query($single_query); } if (!$result) { $error_messages[] = PMA_Message::sanitize($GLOBALS['dbi']->getError()); } else { // The next line contains a real assignment, it's not a typo if ($tmp = @$GLOBALS['dbi']->affectedRows()) { $total_affected_rows += $tmp; } unset($tmp); $insert_id = $GLOBALS['dbi']->insertId(); if ($insert_id != 0) { // insert_id is id of FIRST record inserted in one insert, so if we // inserted multiple rows, we had to increment this if ($total_affected_rows > 0) { $insert_id = $insert_id + $total_affected_rows - 1; } $last_message = PMA_Message::notice(__('Inserted row id: %1$d')); $last_message->addParam($insert_id); $last_messages[] = $last_message; } $GLOBALS['dbi']->freeResult($result); } $warning_messages = PMA_getWarningMessages(); } return array($url_params, $total_affected_rows, $last_messages, $warning_messages, $error_messages, $return_to_sql_query); }
/** * Test for PMA_getWarningMessages * * @return void */ public function testGetWarningMessages() { $warnings = array(array('Level' => 1, 'Code' => 42, 'Message' => 'msg1'), array('Level' => 2, 'Code' => 43, 'Message' => 'msg2')); $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock(); $dbi->expects($this->once())->method('getWarnings')->will($this->returnValue($warnings)); $GLOBALS['dbi'] = $dbi; $result = PMA_getWarningMessages(); $this->assertEquals(array("1: #42 msg1", "2: #43 msg2"), $result); }