Codeigniter to SQL-Server connection using XAMPP - sql-server-2012

Currently my project is running on
XAMPP Version 1.7.3
Codeigniter Version 2.1.4
SQL-Server - Microsoft SQL Server 2012 (SP4-GDR) (KB4057116) - 11.0.7462.6 (X64)
It was running fine but the database is growing day by day and the performance is also getting slower in the same manner. Besides that, due to few other major concerns we are forced to migrate to SQL-Server. Now the database is completely migrated to SQL-Server from MySQL.
The problem is in the connection Codeigniter -> SQL-Server while using XAMPP server. I have tried so many codes that is found in the google but none of these working. One I have is
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'MSSQLSERVER',
'username' => '',
'password' => '',
'database' => 'test', --changed
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
I am a database developer so couldn't make any additions to the code due to lack of ideas. So, can you plese share your ideas to resolve this problem. I am expecting it in detail steps. It’s no problem If I need to upgrade my versions or change anything else, but I can't change the framework itself.

This process was bit easier for me but being a database developer, it gonna bit harder for you. No worries, if you follow the instructions properly then it will work in a single shot
1- Setup CI configuration files and other setup from the following link
https://futbolsalas15.wordpress.com/2014/02/23/7-steps-to-make-sql-server-and-codeigniter-works/
After doing the above changes, It will still remain incomplete in my case and I did the below additional changes
IN FILE: system\database\DB.php
require_once(BASEPATH.'database/DB_driver.php'); --Find this line
$active_record=TRUE; --Add this line below
IN FILE: system\database\DB_driver.php
var $dbdriver = 'mysql'; --Replace `mysql` with `sqlsrv`
SP calling method, suppose you have sp_report with four parameters as below:
--From Mysql
$call_proc = "CALL sp_report('b', 'a', $date_from, $date_to)"
--From SQLServer
$call_proc = "DECLARE #p_report_type CHAR(1) = 'b',
#p_sub_type CHAR(1) = 'a',
#p_date_from VARCHAR(10) = '".$date_from."',
#p_date_to VARCHAR(10) = '".$date_to."'
EXEC sp_report #p_report_type, #p_sub_type, #p_date_from, #p_date_to"
Thats all my friend, hope it will work as expected.

Related

Unable to run migrations on GCP with CakePHP 3.8

I am trying to set up my CakePHP 3.8 project on a GCP "Compute Engine" VM.
I have set up my app.php to use the following DB configuration:
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'user',
'password' => 'password',
'database' => 'dbname',
'prefix' => '',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'log' => false,
'flags' => [
PDO::MYSQL_ATTR_INIT_COMMAND => "SET ##SESSION.sql_mode='';",
// uncomment below for use with Google Cloud SQL
PDO::MYSQL_ATTR_SSL_KEY => CONFIG.'ssl/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => CONFIG.'ssl/client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA => CONFIG.'ssl/server-ca.pem',
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
],
'cacheMetadata' => true,
'log' => false,
My problem happens when I try to run migrations. The site works just fine with the above configuration, however, if I run
$> php bin/cake.php migrations migrate
I get a slew of errors saying that it cannot connect, access denied for user#host.
If I add
'ssl_key' => CONFIG .'ssl/client-key.pem',
'ssl_cert' => CONFIG . 'ssl/client-cert.pem',
'ssl_ca' => CONFIG . 'ssl/server-ca.pem',
I get an error:
Caused by: [PDOException] PDO::__construct(): Peer certificate CN=`gcpname:gcpserver' did not match expected CN=`111.111.111.111' in /var/www/mydomain.com/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 79
I guess this is because the migrations plugin still doesn't pass the flags or custom mysql_attr_* options over to the Phinx connection configuration, see this issue:
https://github.com/cakephp/migrations/issues/374
I don't think there's much that can be done here, other than adding support for flags / attribute options, or using Phinx directly (ie without the Migrations plugin).
I've pushed a PR that would add support for driver specific flags, you might want to give it a try and comment on the issue or the PR whether it works for you (it's for CakePHP 4.x (Migrations 3.x), I'll backport it for CakePHP 3.x (Migrations 2.x) in case it's being accepted):
https://github.com/cakephp/migrations/pull/478

How to update Puppet ini_setting or ini_subsetting resource without section header in conf file?

I wonder if someone can help me with my conf file problem. I need to get the output like below but I get problems in using the inifile. I have put below my code and testing output. My service won't start because of the '[]'. Your comments and ideas are highly appreciated. Thanks!
Expected output
cat /etc/service.conf
info something something...
without section header
setting1=value1
Testings
testscript1.pp
ini_setting {'setx':
ensure => present,
path => '/etc/service.conf',
key_val_separator => '=',
setting => 'setting1',
value => 'value1',
}
output of testscript1.pp
cat /etc/service.conf
info something something...
[setx]
setting1=value1
testscript2.pp
$defaults = {
ensure => present,
path => '/etc/service.conf',
key_val_separator => '=',
}
$settings = {
' ' => {
'setting1' => 'value1',
}
}
create_ini_settings($settings,$defaults)
output of testscript2.pp
cat /etc/service.conf
info something something...
[ ]
setting1=value1
Since I really wanted to delete the [] character because it's causing error during service restart, I used section_prefix => '#',. The first puppet agent run is smooth and working. Problem now is if puppet agent runs on its frequency time (like let's say every hour), it will auto-append details in conf file due to lack of section header. I decided to use ini_subsetting but I'm getting errors with it.
testscript3.pp
ini_subsetting {'subset':
ensure => present,
section => '',
key_val_separator => '=',
path => '/etc/service.conf',
setting => 'setting1',
subsetting => '',
value => 'value1',
}
output of testscript3.pp
Error: Failed to apply catalog: Parameter path failed on Ini_subsetting[subset]: File paths must be fully qualified, not '/etc/service.conf'.
Any suggestions or advises are highly appreciated.
Thank you.
If the file you are managing does not have section markers of some kind, then it is not an INI file, not even in the generalized sense that the puppetlabs/inifile module supports. To the best of my knowledge, you'll need to choose a different approach to managing the file.
You could consider templating the whole file, or writing a custom type and provider for it, but before going to so much trouble, you should consider whether a good old file_line resource from puppetlabs/stdlib would be adequate for your needs.
Have you tried your testscript1.pp with section => ''?
It would look like this:
ini_setting {'setx':
ensure => present,
path => '/etc/service.conf',
key_val_separator => '=',
section => '',
setting => 'setting1',
value => 'value1',
}
And the output would be:
cat /etc/service.conf
info something something...
setting1=value1
Or you could try to use force_new_section_creation => false, as it is true by default and forces the creation of a section, as stated in the module’s reference.
As for your 3rd example, it probably fails because of the blank subsetting parameter. The ini_subsetting resource type requires both setting and subsetting parameters to work.

INSERT data from database into another database, running on different hosts

I'm facing the following problem:
I have two MariaDB databases, running on two different hosts. Both of them are used to run two different websites, each of them having Drupal and CiviCRM installed and running.
Some of the data stored in the contacts table of CiviCRM from website 1 needs to be kept in sync with these same contacts on website 2.
Keeping in sync means : inserting new contacts, and updating existing contacts.
I was wondering if this coud be done via trigger?
I know I can activate remote sql on my cPanel, as I use this to work with Mysql Workbench or similar software.
Any ideas? Would a trigger work? Do I rather need to write some code in another language than SQL?
You can add multiple databases at the same time for your Drupal to connect to in your settings.php:
$databases = [
'HOST1.DATABASE' => [
'default' => [
'driver' => 'mysql',
'username' => '',
'password' => '',
'host' => '127.0.0.1',
'port' => '3306',
'prefix' => '',
'database' => 'contacts',
'collation' => 'utf8mb4_general_ci',
],
],
'HOST2.DATABASE' => [
'default' => [
'driver' => 'mysql',
'username' => '',
'password' => '',
'host' => '127.0.0.1',
'port' => '3306',
'prefix' => '',
'database' => 'contacts_audit',
'collation' => 'utf8mb4_general_ci',
],
],
];
After this you can define in the getConnection() method, which key of the $database array you want to connect.
\Drupal\Core\Database\Database::getConnection('HOST1.DATABASE')
->query('CREATE TRIGGER contacts_after_update AFTER UPDATE ON contacts FOR EACH ROW BEGIN')
->execute();
and
\Drupal\Core\Database\Database::getConnection('HOST2.DATABASE')
->query('INSERT INTO contacts_audit ( contact_id, updated_date, updated_by) VALUES ( NEW.contact_id, SYSDATE(), ); END;')
->execute();
(If you leave the parameter of getConnection() empty, it would connect to the database on $databases['default'] key. Also, you can use setActiveConnection() if you want to work more with the database, which as its name says, sets the active connection to the desired key of $databases)
Hope this helps some way.

How to configure SQLite in Kohana 3?

I'm struggling to find any information on how to configure SQLite in Kohana 3.2. I mainly need to know:
What should I set hostname, database, username and password to (with default user and no password)?
Also, how can I set the path to the SQLite database file?
What should the "type" be? I tried "sqlite" but I get an error Class 'Database_Sqlite' not found.
This is my current configuration options:
'exportedDatabase' => array
(
'type' => 'sqlite',
'connection' => array(
/**
* The following options are available for MySQL:
*
* string hostname server hostname, or socket
* string database database name
* string username database username
* string password database password
* boolean persistent use persistent connections?
*
* Ports and sockets may be appended to the hostname.
*/
'hostname' => $hostname,
'database' => $database,
'username' => $username,
'password' => $password,
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => TRUE,
),
You can use PDO through Database module. The proper way of configuring it looks like this:
'exportedDatabase' => array(
'type' => 'pdo',
'connection' => array(
'dsn' => 'sqlite:/path/to/file.sqlite',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => NULL, /* IMPORTANT- charset 'utf8' breaks sqlite(?) */
'caching' => FALSE,
'profiling' => TRUE,
),
One disadvantage of using PDO in Kohana is that in ORM you have to specify all fields by hand in your model (you should do it anyway for performance reasons) because of how different database systems handle listing of table fields.
There is also real database module created by banditron. You have to remember that's it is NOT a drop-in replacement for Database module and therefore Kohana's ORM will not work with it. Other than that it's pretty neat and has wide support for database systems other than SQLite.
As I found out, Kohana 3.x doesn't actually support SQLite. There's an unsupported module for it and, as far as I can tell, it's not working.
It's easy enough to use PDO though and the syntax is pretty much the same as Kohana's ORM:
$db = new PDO('sqlite:' . $dbFilePath);
$query = $db->prepare('CREATE TABLE example (id INTEGER PRIMARY KEY, something TEXT)');
$query->execute();
$query = $db->prepare("INSERT INTO example (id, something) VALUES (:id, :something)");
$query->bindParam(':id', $id);
$query->bindParam(':something', $something);
$query->execute();
I don't use Kohana, but this should work:
'hostname' => /path/to/your/sql/lite/file.sqlite
'database' => ''
'username' => ''
'password' => ''

Error when creating db with Blog engine

I've installed a RefineryCMS application, and everything was working fine until I decided to install its Blog engine.
We I ran the app migrations (including Blog) from scratch, I've received the following error:
Mysql2::Error: Unknown column 'custom_title' in 'field list': INSERT INTO `pages` (`browser_title`, `path`, `meta_description`, `created_at`, `link_url`, `custom_title_type`, `draft`, `title`, `skip_to_first_child`, `deletable`, `updated_at`, `position`, `rgt`, `custom_title`, `meta_keywords`, `parent_id`, `menu_match`, `lft`, `show_in_menu`, `depth`) VALUES (NULL, NULL, NULL, '2011-03-10 16:32:08', '/blog', 'none', 0, 'Blog', 0, 0, '2011-03-10 16:32:08', 2, 8, NULL, NULL, NULL, '^/blogs?(/|/.+?|)$', 7, 1, NULL)
I've seen this is a known issue, but I cannot find a neat solution for both development and production environments.
BTW, I saw this happening with a custom engine installed by me using rails g engine_name command. The weird thing is that it doesn't happen if you run these migrations after all the previous ones have been run before. It just happens when runnning all the app migrations from scratch.
Any ideas?
UPDATE:
This is my db/seeds/refinerycms_blog.rb file looks like after the comment I've received here:
Page.reset_column_information
User.find(:all).each do |user|
user.plugins.create(:name => "refinerycms_blog",
:position => (user.plugins.maximum(:position) || -1) +1)
end
page = Page.create(
:title => "Blog",
:link_url => "/blog",
:deletable => false,
:position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
:menu_match => "^/blogs?(\/|\/.+?|)$"
)
Page.default_parts.each do |default_page_part|
page.parts.create(:title => default_page_part, :body => nil)
end
But it's still not working. Any ideas?
Add the following to the top of the blog seeds files that it copied into db/seeds/:
Page.reset_column_information