I want to connect to a postgresql database in CodeIgniter via the pdo-driver.
Doing it manually works without any Problems:
$gp = new PDO("pgsql:host=pdca.example.de;port=5432;sslmode=require;dbname=dssprod;",$techUser,$techPW);
$query = $gp->query('select * from table limit 10');
$result = $query->fetchAll( PDO::FETCH_ASSOC );
var_dump($result);
doing the same within CodeIgniter in config\database.php :
$active_group = 'default';
$db['default'] = array(
'dsn' => "pgsql:host=pdca.example.de;port=5432;sslmode=require;dbname=dssprod;",
'username' => $techUser,
'password' => $techPW,
'dbdriver' => 'pdo'
);
and then in a view:
$connect = $this -> load -> database();
var_dump($connect);
--> results in a bool(false)
I can't get a Connection to the db with CodeIgniter, any idea why?
--- edit ---
I tried a config without pdo, same result (false).
$active_group = 'default';
$db['default'] = array(
'hostname' => 'pdca.example.de',
'port' => 5432,
'sslmode' => 'require',
'username' => $techUser,
'password' => $techPW,
'database' => 'dssprod',
'dbdriver' => 'postgre',
'dbprefix' => '',
'pconnect' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'save_queries' => FALSE
);
Related
I'm facing a very tough difficulty since a day ago, i still can't find any solutions regardless all my researches. My hosted website on bluehost has 2 databases, the first one is a mysql database which i connect to database easily and a sql database which i can't connect to it. I learn that i should have extension=php_pdo_sqlsrv_55_nts.dll, extension=php_sqlsrv_55_ts.dll in php.ini according my php version.
If my website is hosted how can i connect to the second sql database ?
My database file is like this :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'ausername',
'password' => 'apassword',
'database' => 'adatabase',
'dbdriver' => 'mysqli',
'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
);
$db['second_database'] = array(
'dsn' => '',
'hostname' => 'aaa.bbb-east-1.rds.amazonaws.com',
'port' => '14733',
'username' => 'aa',
'password' => 'apassword1',
'database' => 'adatabase1',
'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
);
When i load the page i have this error :
Fatal error: Call to undefined function sqlsrv_connect() in /home2/admedica/public_html/admedicall_v1/system/database/drivers/sqlsrv/sqlsrv_driver.php on line 144
I'am using Laravel 5.0 and I make 2 database which is one for system and two for data. when I try to change connection to get data from my second database it tell error
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "barang" does not
exist LINE 1: select * from barang
Here my Controller
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
class MultiController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
$data = DB::connection('pgsql2')->select('select * from barang');
return view('laporan.db')->withData($data);
}
Database.php
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => 'pgsql',
'connections' => [
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'larasimak'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', 'postgres'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'pgsql2' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'simkie_data'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', 'postgres'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
my DotEnv
APP_ENV=local
APP_DEBUG=true
APP_KEY=nlXoLNFcWAD9rtTGXCUSpDdbQxms1ADi
DB_HOST=localhost
DB_DATABASE=larasimak
DB_USERNAME=postgres
DB_PASSWORD=postgres
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
You should set the credential of second database. Current both database are using same credential. Try following for second database:
database.php
'pgsql2' => [
'driver' => 'pgsql',
'host' => env('PS2_DB_HOST', 'localhost'),
'database' => env('PS2_DB_DATABASE', 'simkie_data'),
'username' => env('PS2_DB_USERNAME', 'postgres'),
'password' => env('PS2_DB_PASSWORD', 'postgres'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
]
.evn
PS2_DB_HOST=localhost
PS2_DB_DATABASE=simkie_data
PS2_DB_USERNAME=postgres
PS2_DB_PASSWORD=postgres
I am sending email with CakePHP framework.
Following is the code I have added in function :
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail('gmail');
$Email->from(array(
ADMIN_EMAIL => 'kioui'
));
$Email->to('pankhiwalia#gmail.com');
$Email->subject('test');
$Email->emailFormat('text');
$p = $Email->send();
and under Config/email.php file I have added following smtp settings:
public $smtp = array(
'transport' => 'Smtp',
'from' => array(ADMIN_EMAIL => ADMIN_NAME),
'host' => 'ssl://localhost',
'username' => 'kiouiapp#kioui-apps.com',
'password' => 'Fr00Fr00',
'client' => null,
'log' => true,
'timeout' => '30',
'tls' => false,
'port' => 465,
);
Please tell me did I miss any line?
I am using the getDefaultEntities() function which is run from my installer script. It mostly works, almost all of the attribute config keys reflect properly in the Attributes section of the admin. However the "visible," "visible_on_front" and some of the other properties do not work at all. My custom attribute is always set to not visible, not visible on front end. Can anyone spot what I am doing wrong?
class Ia_AdvancedShipping_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
{
/**
* #return array
*/
public function getDefaultEntities()
{
return array(
'catalog_product' => array(
'entity_model' => 'catalog/product',
'attribute_model' => 'catalog/resource_eav_attribute',
'table' => 'catalog/product',
'additional_attribute_table' => 'catalog/eav_attribute',
'entity_attribute_collection' => 'catalog/product_attribute_collection',
'attributes' => array(
'iaadvancedshipping_profile' => array(
'group' => 'Advanced Shipping',
'label' => 'Shipping Profiles',
'type' => 'varchar',
'input' => 'select',
'source' => 'iaadvancedshipping/product_attribute_source_profiles',
'default' => '0',
'class' => '',
'backend' => '',
'frontend' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'visible_in_advanced_search' => false,
'unique' => false
),
)
)
);
}
}
When looking for a way to provide a cakestrap application with Google Calendar, I came across an older post which mentioned this plugin:
http://www.neilcrookes.com/2009/09/27/get-google-analytics-data-in-your-cakephp/
While trying to add support for Google Calendar it turned out this plugin is not compatible with cakeStrap which I have to use.
I have allready refactored the models, views and controllers but I can't figure out how to convert the gdata-config so it can be used:
<?php
/**
* Coniguration options for Gdata API
*/
class GDATA_CONFIG {
var $analytics = array(
'datasource' => 'gdata',
'driver' => 'analytics',
'email' => '',
'passwd' => '',
'profileId' => '',
'source' => 'CakePHP',
);
var $youtube = array(
'datasource' => 'gdata',
'driver' => 'youtube',
'email' => '',
'passwd' => '',
'source' => 'CakePHP',
);
var $picasa = array(
'datasource' => 'gdata',
'driver' => 'picasa',
'email' => '',
'passwd' => '',
'source' => 'CakePHP',
'cache' => true,
'cacheDuration' => '+1 hours'
);
var $calendar = array(
'datasource' => 'gdata',
'driver' => 'calendar',
'email' => '',
'passwd' => '',
'source' => 'CakePHP',
);
}
?>
This is my first time working with cakePHP so any help is appreciated.
Custom configuration format (using PHP reader) is like:
<?php
$config = array('youtube' =>
'datasource' => 'gdata',
'driver' => 'youtube',
'email' => '',
'passwd' => '',
'source' => 'CakePHP'
));
You can use Configure::load('configuration_file_name.php') to load configuration file and Configuration::read('configuration_array_key') to read configuration variables.
See http://book.cakephp.org/2.0/en/development/configuration.html#configure-class for more information.