本文整理汇总了PHP中JDatabase::splitSql方法的典型用法代码示例。如果您正苦于以下问题:PHP JDatabase::splitSql方法的具体用法?PHP JDatabase::splitSql怎么用?PHP JDatabase::splitSql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JDatabase
的用法示例。
在下文中一共展示了JDatabase::splitSql方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSplitSql
/**
* Tests the JDatabase::splitSql method.
*
* @return void
*
* @since 12.1
*/
public function testSplitSql()
{
$this->assertThat(
$this->db->splitSql('SELECT * FROM #__foo;SELECT * FROM #__bar;'),
$this->equalTo(
array(
'SELECT * FROM #__foo;',
'SELECT * FROM #__bar;'
)
),
'splitSql method should split a string of multiple queries into an array.'
);
}
示例2: runUpdateSQL
private function runUpdateSQL($version)
{
$db = JFactory::getDBO();
$buffer = file_get_contents(JPATH_ADMINISTRATOR . '/components/com_jfbconnect/install/sql/updates/' . $version . '.' . $this->getDbType() . '.sql');
// Graceful exit and rollback if read not successful
if ($buffer === false) {
JError::raiseWarning(1, JText::_('JLIB_INSTALLER_ERROR_SQL_READBUFFER'));
return false;
}
// Create an array of queries from the sql file
//$queries = JDatabaseDriver::splitSql($buffer); // Joomla 3.x+
$queries = JDatabase::splitSql($buffer);
$update_count = 0;
if (count($queries) != 0) {
// Process each query in the $queries array (split out of sql file).
foreach ($queries as $query) {
$query = trim($query);
if ($query != '' && $query[0] != '#') {
$db->setQuery($query);
if (!$db->execute()) {
JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)), JLog::WARNING, 'jerror');
return false;
}
$update_count++;
}
}
}
// All done. Update the db_version row to the latest number
$query = $db->getQuery(true);
$query->select($db->qn('value'))->from('#__jfbconnect_config')->where($db->qn('setting') . '=' . $db->q('db_version'));
$db->setQuery($query);
$ver = $db->loadResult();
$query->clear();
if ($ver) {
$query->update('#__jfbconnect_config')->where($db->qn('setting') . '=' . $db->q('db_version'))->set($db->qn('value') . '=' . $db->q($version))->set($db->qn('updated_at') . '= NOW()');
} else {
$query->insert('#__jfbconnect_config')->columns($db->qn('setting') . "," . $db->qn('value') . ',' . $db->qn('created_at') . "," . $db->qn('updated_at'))->values($db->q('db_version') . ',' . $db->q($version) . ', NOW(), NOW()');
}
$db->setQuery($query);
$db->execute();
}