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
Related
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 :)
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
),
)
new to laravel framework, I am running multiple database connections for a project I am working on. Just a simple test against one of the mysql instance,
<p>{{ $data2 = DB::connection('mysql2')->table('test')->get() }}</p>
gives a simple dump but when run simmilar test against the ms sql server 2012, it errors out
<p>{{ $data3 = DB::connection('sqlsrv')->table('test1')->get() }}</p>
The error is:
ErrorException in helpers.php line 519:
Method Illuminate\Support\Collection::__toString() must return a string value
my db config is similar to other examples I have seen posted online.
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'SQL3.company.ca'),
'database' => env('DB_DATABASE', 'test'),
'username' => env('DB_USERNAME', 'test'),
'password' => env('DB_PASSWORD', '#######'),
'collation' => 'SQL_Latin1_General_CP1_CI_AS',
'charset' => 'latin1',
'prefix' => '',
],
Did I set up something wrong? any direction I should be looking at?
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 used this in my UserController
require_once 'Zend/Controller/Action.php';
AND
public function processAction()
{
$params = array('host' =>'localhost',
'username' =>'root',
'password' =>'',
'dbname' =>'zend'
);
$DB = new Zend_Db_Adapter_Pdo_Mysql($params);
$request = $this->getRequest();
$data = array('first_name' => $request->getParam('first_name'),
'last_name' => $request->getParam('last_name'),
'user_name' => $request->getParam('user_name'),
'password' => md5($request->getParam('password'))
);
$DB->insert('user', $data);
$this->view->assign('title','Registration Process');
$this->view->assign('description','Registration succes');
}
Which displayed following error. I do not have the php.ini access.
Fatal error: Class 'Zend_Db' not found in D:\xampp\xampp\htdocs\zend-test\zend-demo\application\controllers\UserController.php on line 42
i.e. on this line
$params = Zend_Db::factory('Pdo_Mysql', array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'zend'
));
Thanks in advance!
Mangesh
Maybe this will help.
Tutorial on how to setup a working Zend framework
http://usingzendframework.blogspot.com/2007/01/setting-up-zend-framework.html
You need to include all of the Zend libraries you use - not just
equire_once 'Zend/Controller/Action.php';
Also, you need to do what Jurka specified - a much better and cleaner practice.