Database mysql proxy error while connect with YII - php

I have configure mysql cluster with one master and one slave. Configured mysql proxy as common ip to access the servers. when i connect using mysql command its successfully connecting. But when i tried to access mysql proxy in yii application I am getting following error
2011/12/01 05:25:40 [error] [exception.CDbException] SQLSTATE[42000]
[1049] Unknown database 'PortalDB' 2011/12/01 05:25:40 [error]
[exception.CDbException] exception 'CDbException' with message
'CDbConnection failed to open the DB connection.' in
/var/www/YII/yii-1.1.8.r3324/framework/db/CDbConnection.php:370
Below is the db configuration in YII
'db'=>array(
'connectionString' => 'mysql:host=xxxx;dbname=PortalDB;port=4040;',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'mysql',
'charset' => 'utf8',
'queryCachingDuration' => 300,
'enableParamLogging' => true
),
'db2'=>array(
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=xxxx;dbname=PortalDB;port=4040;',//devdbserver.c27hiz0xxzr5.us-east-1.rds.amazonaws.com
'emulatePrepare' => true,
'username' => 'root',
'password' => 'mysql',
'charset' => 'utf8',
'queryCachingDuration' => 300,
'enableParamLogging' => true
),

Related

How to connect SQLserver 2014 to Laravel app

How can I connect my Laravel to my SQL SERVER 2014?
TRIED METHODS
first
I tried to use sqlsvr in my .env and change my config > database.php to 'default' => env('DB_CONNECTION', 'sqlsvr').
"my..." replace my actual credentials.
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => 'myServerName',
'port' => '1433',
'database' => 'myDatabaseName',
'username' => 'myUserName',
'password' => 'myPassword',
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
But it throws an error of:
Database [sqlsrv] not configured
second
I tried some method using odbc connection find some package on GitHub but no luck, some have errors and some not supported by Laravel 5+
OTHER INFO
I'm using Larave 6.0.1 and SQL Server 2014.
Any help will do.

Cakephp is trying to connect to my machine instead of the database I've setup

I'm having a hard time while trying to run a local project in my computer. It's built on cakephp 3.2.x, I run it with cakephp's dev server (bin/cake server), but the project crashes when it tries to paginate something for the user landing page:
Error: SQLSTATE[HY000] [1045] Access denied for user 'scqadev'#'192.168.1.63' (using password: YES)
Here comes the main headache: 192.168.1.63 is the IP of my computer, but my datasources aren't pointing to my machine. I want it to connect to a database in 192.168.1.43. Here's my config/app.php file:
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => '192.168.1.43',
'username' => 'scqadev',
'password' => 'scqadev',
'database' => 'scqadev',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'log' => false,
'quoteIdentifiers' => false,
],
'csd' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => '192.168.1.43',
//'port' => 'nonstandard_port_number',
'username' => 'csd',
'password' => 'csd',
'database' => 'csd',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
'log' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
],
],
The problem happens in this line, inside a controller:
$this->set('analises', $this->paginate($this->Analises));
And my 'Analise' entity points to the default datasource (there is no custom datasource config in src/Model/Entity/Analise.php).
So where is this configuration coming from? Why is cakephp trying to log in my computer's database instead of 192.168.1.43's ?
It's not trying to connect to your computer. The application is trying to connect to the correct datasource as 'scqadev'#'192.168.1.63'. You should make sure that such user is defined in your database. Or (probably better) a user called 'scqadev'#'%'.

Cannot connect to Google Cloud SQL through Google App Engine with Pdo_Mysql in ZF2

I have been trying to solve this issue already for a few days without any results. When using default php pdo object I can connect to the database:
$db = new \PDO('mysql:unix_socket=/cloudsql/project-id:database-instance;dbname=test',
'root', // username
'' // password
);
But when trying to connect with ZF2 adapter the connection just times out.
'db' => array(
'driver' => 'Pdo_Mysql',
'database' => 'test',
'username' => 'root',
'unix_socket' => '/cloudsql/project-id:database-instance',
),
I am quite sure that the problem is somehow with the unix_socket as I can connect to the Cloud SQL server from my localhost directly without socket:
'db' => array(
'driver' => 'Pdo_Mysql',
'host' => 'xxx.xxx.xxx.xxx',
'database' => 'test',
'username' => 'user',
'password' => 'password',
),
What I am missing?
unix_socket isn't a recognized option for the pdo driver (https://github.com/zendframework/zf2/blob/master/library/Zend/Db/Adapter/Driver/Pdo/Connection.php#L164). Try this instead
'db' => array(
'dsn' => 'mysql:unix_socket=/cloudsql/project-id:database-instance;dbname=test',
'username' => 'user',
'password' => 'password',
)

Kohana CLI Database Error

I am getting this error when I am accessing ORM in a script run from the command line:
Database_Exception [ 2 ]: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) ~ MODPATH/database/classes/kohana/database/mysql.php [ 67 ]
This is my directory structure
application
--bootstrap.php
modules
content
--index.php
system
This is my database config:
$database_config = array
(
'default' => array
(
'type' => 'mysql',
'connection' => array(
'hostname' => 'localhost',
'database' => 'driverslife',
'username' => 'root',
'password' => 'root',
'persistent' => FALSE,
'port' => 8889
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => TRUE,
),
);
When I echo MODPATH in the command line, it shows me the right path(slash appended). Is there anything I might be missing?
Use 127.0.0.1 instead of localhost in your config. More info here:
Error when connecting to MySQL using PHP/PDO

configuring database connection in Yii framework

In the main.php file of the Yii framework, there are some configuration options. This is how it sets up mysql
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
),
On my MAMP system, I have to specify the port as 8889. How would I add it into this?
thanks
I added the port like this and it seems to work
'db'=>array(
'connectionString' => 'mysql:host=localhost;port=8889;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
),
can you not add it here to your connectionString
'connectionString' => 'mysql:host=localhost;dbname=testdrive;port=8889',

Categories