I am having trouble to add options for laravael config/database.php;
TrustServerCertificate
Encryption
I am getting below error when trying to connect to MSSQL database;
SQLSTATE[08001]: [Microsoft][ODBC Driver 18 for SQL Server]SSL
Provider: [error:1416F086:SSL
routines:tls_process_server_certificate:certificate verify failed:self
signed certificate]
database information is below without TrustServerCertificate&Encryption
'000002' => [
'driver' => 'sqlsrv',
'odbc_driver' => '{ODBC Driver 18 for SQL Server}',
'host' => 'WWW.XXX.YYY.ZZZ',
'database' => 'database_name',
'username' => 'user_name',
'password' => 'pass_word',
'port' => '1433',
'prefix' => '',
'charset' => 'utf8',
]
but when I try with RAW php with below code including TrustServerCertificate it works;
<?php
$host = "WWW.XXX.YYY.ZZZ";
$user = "user_name";
$password = "pass_word";
$dbname="database_name";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_EMPTY_STRING
];
try {
$connection = new PDO("sqlsrv:Server=$host,1433; Database=$dbname;TrustServerCertificate=1", $user, $password);
} catch(PDOException $e) {
die("Database connection failed: " . $e->getMessage());
exit;
}
echo"Connection Successful";
?>
How can I add this to Laravels database configuration information?
I tried multiple ways as below but didn't help;
TrustServerCertificate = 1,
TrustServerCertificate = '1',
TrustServerCertificate = 'true',
TrustServerCertificate = true,
trust_server_certificate = 1,
trust_server_certificate = '1',
trust_server_certificate = 'true',
trust_server_certificate = true,
Should it be under an options array?
What should be the setting for ODBC18 driver?
Thanks
If anyone bumps into this issue, just rollback to ODBC driver 17. ODBC driver 18 comes with SSL/Certificate and Encryption requirement as default. If you are able to acquire ssl licences for your servers, do use version 18.
Happy coding :)
Related
I get the following error on my cakePHP2.7 project when I move the code to my new server. The code works fine on all my existing servers.
we are using aws SES as mail service.
We created a sample file as instructed by https://docs.aws.amazon.com/ses/latest/dg/send-using-smtp-programmatically.html and that also works fine.
Any help is appriciated
code for your reference
public $mailarr = array(
'host'=>'email-smtp.us-west-2.amazonaws.com',
'port' => 587,
'username' => 'XXXXXXXXXXXXXXX',
'password' => 'XXXXXXXXXXX',
'tls'=>true,
'returnPath'=>'xxx#xxx.com',
'transport' => 'Smtp',
'from' => array('xxx#xxx.com' => 'Alert!'),
'emailFormat' => 'html',
'timeout' => 300,
);
I have tried to add the below as part of my mailarr but the error still persists
'context' => array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
),
)
When I was using ZF1, I had an ini file with db connection information (i.e. mysql, pgsql, mssql, etc...)
modulename.adapter = PDO_MYSQL
modulename.params.host = xxx.xxx.x.xx
modulename.params.username = username
modulename.params.password = password
modulename.params.dbname = databasename
and in my model, I would extends Zend_Db_Table and do the following in my
public function _construct() {
$dbconfig = Zend_Registry::get('dbProfiles');
$this->db = Zend_Db::factory($dbconfig->modulename->adapter,
$dbconfig->modulename->params);
}
in some function, I have the following code
$sql = "SELECT * FROM Table";
$result = $this->db->query($sql);
while($row =$result->fetch()) {
//... do something
}
How can I do something similar to this in ZF3? Connecting multiple database types, querying different tables, and fetching my results?
Thank you.
In your configuration set as many database adapters as you have databases:
'db' => [
'adapters' => [
'Application\Db\Db1Adapter' => [
'driver' => 'Pdo_Mysql',
'Dsn' => 'mysql:dbname=Your_db_1_name;host=your_host;charset=utf8',
'password' => 'your_password',
'username' => 'your_username',
],
'Application\Db\Db2Adapter' => [
'driver' => 'Pdo_Mysql',
'Dsn' => 'mysql:dbname=Your_db_2_name;host=your_host;charset=utf8',
'password' => 'your_password',
'username' => 'your_username',
]
]
],
Then call the adapter in service manager factories to create tablegateway or just pass the adapter to the controller:
use \Application\Db\Db1Adapter;
...
$db1Adapter = $container->get(Db1Adapter::class);
...
I have been asked to use an external SMTP server with the following instructions:
"We expect you to connect to port 25 in cleartext, then issue a STARTTLS to commence TLS/SSL. Then log in"
Is this possible and if so, how should I do it? As I understand it, this is different to setting the TLS to true in the smtp connection array, is that right?
UPDATE
Plodding towards victory here. Looking at the code in SmtpTransport.php I can see it matches up with the spec linked in the comments (obviously) but the block 102-107 seems to set the host to either client or localhost - I'm setting the remote ip in the host configuration. Am i doing it wrong?
Cakes code:
protected function _connect() {
$this->_generateSocket();
if (!$this->_socket->connect()) {
throw new SocketException(__d('cake_dev', 'Unable to connect to SMTP server.'));
}
$this->_smtpSend(null, '220');
if (isset($this->_config['client'])) {
$host = $this->_config['client'];
} elseif ($httpHost = env('HTTP_HOST')) {
list($host) = explode(':', $httpHost);
} else {
$host = 'localhost';
}
try {
$this->_smtpSend("EHLO {$host}", '250');
if ($this->_config['tls']) {
$this->_smtpSend("STARTTLS", '220');
$this->_socket->enableCrypto('tls');
$this->_smtpSend("EHLO {$host}", '250');
}
} catch (SocketException $e) {
if ($this->_config['tls']) {
throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.'));
}
try {
$this->_smtpSend("HELO {$host}", '250');
} catch (SocketException $e2) {
throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection.'));
}
}
}
My Email Config:
public $smtp = array(
'transport' => 'Smtp',
'from' => array('me#example.com' => 'my name'),
'host' => 'secretipaddress',
'port' => 25,
'timeout' => 30,
'username' => 'me#example.com',
'password' => 'secretpassword',
'client' => null,
'log' => true,
'tls' => true
);
Enable the 'tls' to true in your config file app.php.
It work for me and in cakephp 3.1 with gmail smtp
I connect to a remote database from within my symfony2 app with this code
$connectionFactory = $this->container->get('doctrine.dbal.connection_factory');
$conn = $connectionFactory->createConnection(array(
'driver' => 'pdo_mysql',
'user' => 'mattias',
'password' => 'fdfsdf',
'host' => 'fs1.rrtgy.se',
'dbname' => 'csmedia',
));
return $conn;
Is there a parameter I can set to do it using SSL?
The equivalent of something like this:
$link = mysql_connect("192.112.7.18","test","testpass",false,MYSQL_CLIENT_SSL)
You could try add to createConnection array 'driverOptions'
$conn = $connectionFactory->createConnection(array(
'driver' => 'pdo_mysql',
'user' => 'mattias',
'password' => 'fdfsdf',
'host' => 'fs1.rrtgy.se',
'dbname' => 'csmedia',
'driverOptions' => array(
PDO::MYSQL_ATTR_SSL_CA =>'/path/to/ssl-ca.pem'
),
));
More info about MYSQL SSL constants.
Notice, that some constants were added at php 5.3.7
However, SSL options are silently ignored in (at least) version 5.3.8: see the bug report.
I tried out Zend Framework 2 skeleton application and its working fine in
Zend Server 5.6 (PHP Version 5.4.0 apache 2.2.21 MYSQL 5.0.10). But i want Zend Framework 2 to connect with MS SQL 2008. I tried the following but it doesn't work and throws exception
" An invalid parameter was passed to sqlsrv_execute. "
'db' => array(
'driver' => 'sqlsrv',
'hostname' => 'testserver\test',
'Database' => 'payroll',
'UID' => 'sa',
'PWD' => '123456'
),
whats wrong with above db array? please suggest me with correct connection string
FYI :
i have tested php 5.4 and MS SQL 2008 connection and it works fine, the following connection was established successfully.
/*
$serverName = "testserver\test"; //serverName\instanceName
$connectionInfo = array( "Database"=>"payroll", "UID"=>"sa", "PWD"=>"123456");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "---------- Connection established --------------------.<br />";
$sql = "select * from users";
$stmt = sqlsrv_query($conn, $sql);
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
echo $row['id'].", ".$row['username']."<br />";
}
} else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
*/
As you did not technically "answered" your own question, I will do it for you.
Try these connection parameters, they might work using PDO :
'db' => array(
'driver' => 'pdo',
'dsn' => 'sqlsrv:database=payroll;Server=testserver\test',
'username' => 'sa',
'password' => '123456'
),
In your global.php file add the below connection detail:
'db' => array(
'driver' => 'Sqlsrv',
'hostname' => 'SERVERNAME',
'Database' => 'DBNAME',
'uid' => 'username',
'pwd' => 'password',
)
To add sqlsrv driver, download it from url : http://www.microsoft.com/en-us/download/details.aspx?id=20098
Add extension in your php ini file like this and then restart apache server:
extension=php_sqlsrv_53_ts.dll