This question already has an answer here:
PHP PDO initialization fails due to "double port" - Uncaught PDOException: SQLSTATE[HY000] [2002]
(1 answer)
Closed 5 years ago.
Before i've installed my app and works fine but when i make new installation on other device with same code and config,
i got error when trying to connect tunneling mysql with pdo extensions on yii 1.
The error message like this:
CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Failed to parse address "localhost:3307:3306"
I just want to connect with port 3307 but :3306 auto included
I've tried some method but keep not working
My main config:
'db' => array(
'class' => 'CDbConnection',
'connectionString' => !empty($ini['db']['conn_str'])
? $ini['db']['conn_str'] : 'mysql:host=localhost;dbname=xxx',
'username' => !empty($ini['db']['user'])
? $ini['db']['user'] : 'root',
'password' => isset($ini['db']['password'])
? $ini['db']['password'] : 'xxx',
'tablePrefix' => !empty($ini['db']['prefix'])
? $ini['db']['prefix'] : 'dcl_',
'emulatePrepare' => true,
'charset' => 'utf8',
'schemaCachingDuration' => 86400,
'enableParamLogging' => TRUE,
'enableProfiling' => TRUE,
),
'dbmm' => array(
'class' => 'CDbConnection',
'connectionString' => !empty($ini['dbmm']['conn_str'])
? $ini['dbmm']['conn_str'] : 'mysql:host=localhost;dbname=xxx',
'username' => !empty($ini['dbmm']['user'])
? $ini['dbmm']['user'] : 'root',
'password' => isset($ini['dbmm']['password'])
? $ini['dbmm']['password'] : 'xxx',
'tablePrefix' => !empty($ini['dbmm']['prefix'])
? $ini['dbmm']['prefix'] : 'mm_',
'emulatePrepare' => true,
'charset' => 'utf8',
'schemaCachingDuration' => 86400,
'enableParamLogging' => TRUE,
'enableProfiling' => TRUE,
'attributes' => array(
PDO::MYSQL_ATTR_LOCAL_INFILE => true
),
),
'dbantrian' => array(
'class' => 'CDbConnection',
'connectionString' => !empty($ini['dbantrian']['conn_str'])
? $ini['dbantrian']['conn_str'] : 'mysql:host=localhost;dbname=xxx',
'username' => !empty($ini['dbantrian']['user'])
? $ini['dbantrian']['user'] : 'root',
'password' => isset($ini['dbantrian']['password'])
? $ini['dbantrian']['password'] : 'xxx',
'emulatePrepare' => true,
'charset' => 'utf8',
'schemaCachingDuration' => 86400,
'enableParamLogging' => TRUE,
'enableProfiling' => TRUE,
),
My .ini file:
[db]
conn_str = "mysql:host=localhost:3307;dbname=xxx"
user = "root"
password = "xxx"
prefix = "dcl_"
[dbmm]
conn_str = "mysql:host=localhost:3307;dbname=xxx"
user = "root"
password = "xxx"
prefix = "mm_"
[dbantrian]
conn_str = "mysql:host=localhost:3307;dbname=xxx"
user = "root"
password = "xxx"
The tools what i use:
Ubuntu 16
Ajenti V
Nginx
PHP 5.6
PDO and PDO Mysql
MariaDB 5.7
I can't use the solution from PHP PDO initialization fails due to "double port" - Uncaught PDOException: SQLSTATE[HY000] [2002] because i disallowed to update core files of yii
I don't know what i miss
Thanks before and sorry for my english
Update:
My app on old device has error (like on my new app) after sudo apt upgrade
Setting up php5.6-common (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-curl (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-sqlite3 (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-mbstring (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-xml (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-gd (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-readline (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-mcrypt (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-json (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-mysql (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-opcache (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-cli (5.6.30-10+deb.sury.org~xenial+2) ...
Setting up php5.6-fpm (5.6.30-10+deb.sury.org~xenial+2) ...
NOTICE: Not enabling PHP 5.6 FPM by default.
NOTICE: To enable PHP 5.6 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php5.6-fpm
NOTICE: You are seeing this message because you have apache2 package installed.
Setting up php-msgpack (2.0.2+0.5.7-1+deb.sury.org~xenial+2) ...
Setting up php-mysql (1:7.1+52+deb.sury.org~xenial+1) ...
Setting up php-pgsql (1:7.1+52+deb.sury.org~xenial+1) ...
The configuration string should look like:
mysql:host=localhost;port=3307;...
The port part must be separated from the host.
Related
I created an Amazon MQ broker:
Select broker engine: RabbitMQ 3.8.6
Single-instance broker
Network and security: Public access
VPC and subnets: Use the default VPC and subnet(s)
I have tried two libraries: from RabbitMQ manual and Enqueue\AmqpExt
Either of them cannot connect to Amazon (with docker container all works fine. But I want to try AMAZON MQ.
I used code below:
use Enqueue\AmqpExt\AmqpConnectionFactory;
use PhpAmqpLib\Connection\AMQPSSLConnection;
$connectionFactory = new AmqpConnectionFactory([
'host' => 'b-da219bXXXXXXXXXXXX86a.mq.us-east-1.amazonaws.com',
'port' => 5671,
'vhost' => '/',
'user' => 'xxxx',
'pass' => 'xxxx', // I can login with this to rabbit admin panel
'persisted' => false,
'ssl_on' => false,
'ssl_verify' => false,
]);
$c = $connectionFactory->createContext();
$queue = $c->createQueue('emails');
$c->declareQueue($queue);
Result:
Library error: connection closed unexpectedly - Potential login failure.
With 'ssl_on' => true the same error.
I don't know can it be happen because I didn't provide ssl cert to amazon.
If so, how to fix it?
I've had success with php-amqplib, and I am actually not using the newest version (I am on v2.12.3). I can connect using this:
$connection = new AMQPSSLConnection($host, $port, $user, $pass, $vhost, ['verify_peer_name' => false], [], 'ssl');
I found that I had to set 'verify_peer_name' => false, or else I just got a unable to connect to ssl://localhost:5671 (Unknown error) error, but I was also port-forwarding through localhost.
Amazon MQ broker (RabbitMQ specifically) is using SSL by default (you can notice that connection string starts with amqps, not amqp
In your case, you should set to true ssl_on and ssl_verify options
Answered by #Eugene K in a sub-comment:
You need to add the DSN to the SSLOptions array, and you need to use a AMQPSSLConnection instead of an AMQPStreamConnection
$this->connection = new AMQPSSLConnection(
'myhost.mq.eu-west-1.amazonaws.com',
'5671',
'username',
'xxx',
'/',
[
'dsn' => 'amqps:'
]
);
I see you installed amqp-ext and using it's ConnectionFactory
use Enqueue\AmqpExt\AmqpConnectionFactory; but
If you are using php-enqueue and want to connect to AWS AMQ RabbitMQ you should install and use enqueue/amqp-lib instead of enqueue/amqp-ext
and connection details
use Enqueue\AmqpLib\AmqpConnectionFactory;
new AmqpConnectionFactory([
'host' => env('RABBITMQ_HOST'),
'port' => env('RABBITMQ_PORT', 5672),
'vhost' => env('RABBITMQ_DEFAULT_VHOST'),
'user' => env('RABBITMQ_USERNAME'),
'pass' => env('RABBITMQ_PASSWORD'),
'persisted' => false,
'ssl_on' => true,
'ssl_verify' => true,
]);
I have to test Echofish to centralize log files.
I followed the installation procedure , but this one does not seem up to date.
When that connects me to the web interface , I get an error 500 - "CDbConnection failed to open the DB connection."
Error 500 in Echofish
When manually connects me to the database with " mysql -u echofish -p ETS_echofish ", it's works.
I changed the file db.php following documentation.
<?php
return array(
'connectionString' => 'mysql:host=localhost;port=3306;dbname=ETS_echofish',
'emulatePrepare' => true,
'username' => 'echofish',
'password' => 'my_password',
'charset' => 'utf8',
);
I use CentOS 7
Echofish uses Yii
Thanks
Please try this
<?php
return array(
'connectionString' => 'mysql:host=localhost;port=3306;dbname=ETS_echofish',
'emulatePrepare' => false,
'username' => 'echofish',
'password' => 'my_password',
'charset' => 'utf8',
);
Found the following solution which avoided disabling SELinux: Connect DATABASE Error TYPE: 2002: Permission denied
Basicly setsebool -P httpd_can_network_connect_db 1
That solved my problem. Hope it helps.
I'm having a try at connecting to a MSSQL DB using PHP on a Linux system.
Using tsql -S <dbConfig> or tsql -H <dbHost> successfully connects to the database (with user credentials of course). However, using the same host and config within PDO returns a failed to connect to host adapter error.
The issue seems to be living somewhere between PHP PDO and, I'm assuming freetds.
The debug looks like this:
PDOException in Connector.php line 55:
SQLSTATE[01002] Adaptive Server connection failed (MYHOST.database.windows.net) (severity 9)
in Connector.php line 55
at PDO->__construct('dblib:host=MYHOST.database.windows.net;dbname=RecipeDB;charset=utf8', 'MYUSER#MYHOST', 'MYPASSWORD', array('0', '2', '0', false)) in Connector.php line 55
at Connector->createConnection('dblib:host=MYHOST.database.windows.net;dbname=RecipeDB;charset=utf8', array('driver' => 'sqlsrv', 'host' => 'MYHOST.database.windows.net', 'database' => 'RecipeDB', 'username' => 'MYUSER#MYHOST', 'password' => 'MYPASSWORD', 'charset' => 'utf8', 'prefix' => '', 'name' => 'remoteRecipes'), array('0', '2', '0', false)) in SqlServerConnector.php line 32
at SqlServerConnector->connect(array('driver' => 'sqlsrv', 'host' => 'MYHOST.database.windows.net', 'database' => 'RecipeDB', 'username' => 'MYUSER#MYHOST', 'password' => 'MYPASSWORD', 'charset' => 'utf8', 'prefix' => '', 'name' => 'remoteRecipes')) in ConnectionFactory.php line 61
at ConnectionFactory->Illuminate\Database\Connectors\{closure}()
It seems I'd managed to remove the line containing [global] from my /etc/freetds.conf file. Once I replaced it PDO was able to make a call to the database.
Below is what it looks like for me:
[global]
# TDS protocol version
; tds version = 4.2
tds version = 8.0
client charset = UTF-8
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
dump file = /tmp/freetds.log
debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
[testConnection]
host = MYHOST.database.windows.net
port = 1433
tds version = 8.0
I'm trying to connect to an SQL server using CodeIgniter. If I use the sqlsrv driver - I get a fatal error message and if I use the odbc driver - I get an 'Unable to connect to your database server using the provided settings error message. Does anyone know how to fix this problem??? I don't mind how, I just want Codeigniter to connect to the SQL Server Database.
This is the database config file
$db['otherdb']['hostname'] = '195.234.10.55\SQLEXPRESS';
$db['otherdb']['username'] = 'username';
$db['otherdb']['password'] = 'password';
$db['otherdb']['database'] = 'ONEDB';
$db['otherdb']['dbdriver'] = 'odbc'; // Done this in both ODBC and SQLSRV
$db['otherdb']['dbprefix'] = '';
$db['otherdb']['pconnect'] = TRUE;
$db['otherdb']['db_debug'] = TRUE;
$db['otherdb']['cache_on'] = FALSE;
$db['otherdb']['cachedir'] = '';
$db['otherdb']['char_set'] = 'utf8';
$db['otherdb']['dbcollat'] = 'utf8_general_ci';
$db['otherdb']['swap_pre'] = '';
$db['otherdb']['autoinit'] = TRUE;
$db['otherdb']['stricton'] = FALSE;
Thanks
(Don't mean to resurrect an old post, but just in case others are looking for the answer, and because this post came up during my search...)
A short step-by-step guide to connect to SQL_server from CodeIgniter 3 using native driver:
First of all download PHP for SQL_server Microsoft native driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098. Take care to choose the one that fits your setup.
Install it to the PHP extension directory.
Configure the new extension in PHP.ini. uncommenting or appending the line (depending on the choosen driver version). I.e.:
extension = php_sqlsrv_55_ts.dll
Restart Apache.
Now your PHP setup is able to connect to SQL_server databases.
Set up your CodeIgniter database connection by configuring application/config/database.php like
<?php
// native-driver connection
$db['default'] = array(
'dsn' => '',
'hostname' => 'SERVER\SQLEXPRESS',
'username' => 'test_user',
'password' => 'test_password',
'database' => 'test01',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => 'application/cache',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE,
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Tested from CodeIgniter 3.0.1 on SQL_server 2008 R2 and SQL_server 2014 express.
I installed jobberBase using automatic installation (softaculous) on arvixe. As this was all automatic installation chances of any errors are rare. Still I did double checked that database got created fine; also the configuration looked fined.
I saw this errors on many other threads too but couldnt find a solution anywhere ; so looks like its a common installation problem. Most probably the php are not able to connect to DB ! Any help would be highly appreciated.
Warning: mysqli::mysqli() expects parameter 5 to be long, string given in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 20
Warning: mysqli::query() [mysqli.query]: Couldn't fetch Db in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 72
Warning: mysqli_error() [function.mysqli-error]: Couldn't fetch Db in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 73
Warning: mysqli::query() [mysqli.query]: Couldn't fetch Db in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 31
Warning: mysqli_error() [function.mysqli-error]: Couldn't fetch Db in /home/muskete3/public_html/jobber/_includes/class.Db.php on line 32
Fatal error: Call to a member function fetch_assoc() on a non-object in /home/muskete3/public_html/jobber/_includes/class.JobberSettings.php on line 23
My configuration file is :
<?php
/**
* Define environments
*
*/
// local (http://localhost/jobberbase/public)
$__instances['local'] = array(
// should be a unique part of the url (or the entire url if you wish)
'prefix' => 'www.jobs41.net',
// mysql credentials
'db_host' => 'localhost',
'db_port' => 3306,
'db_user' => '***',
'db_password' => '***',
'db_name' => '***',
'db_prefix' => '',
// your site's full url
'app_url' => 'http://www.jobs41.net/jobber/',
// error reporting
'ini_error_reporting' => E_ALL,
'ini_display_errors' => 'On',
// environment setting 1 (use 'local' for localhost/testing OR 'online' for live, production environment)
'location' => 'local',
// environment setting 2 (use 'dev' together with 'local' in the previous setting OR 'prod' with 'online')
'environment' => 'dev',
//'apache_mod_rewrite', 'iis_url_rewrite' -microsoft URL Rewrite module, 'iis_isapi_rewrite'
'rewrite_mode' => 'apache_mod_rewrite'
);
// live (http://www.yourjobberbasedomain.com)
$__instances['live'] = array(
'prefix' => 'www.jobs41.net',
'db_host' => 'localhost',
'db_port' => 3306,
'db_user' => 'muskete3_jobb563',
'db_password' => '6Sn82hxv7P',
'db_name' => 'muskete3_jobb563',
'db_prefix' => '',
'app_url' => 'http://www.jobs41.net/jobber/',
'ini_error_reporting' => E_ALL,
'ini_display_errors' => 'Off',
'location' => 'online',
'environment' => 'prod',
'rewrite_mode' => 'apache_mod_rewrite'
);
Previously I had installed it not as root directory; hence it was installed inside public_html/job.. Now when i installed it again in root directory it worked fine.