Kohana CLI Database Error - php

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

Related

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'#'%'.

Artisan unable to access environment variables from $_ENV

Any artisan command I enter into the command line throws this error:
$ php artisan
<?
return array(
'DB_HOSTNAME' => 'localhost',
'DB_USERNAME' => 'root',
'DB_NAME' => 'pc_booking',
'DB_PASSWORD' => 'secret',
);
PHP Warning: Invalid argument supplied for foreach() in /home/martin/code/www/pc_backend/vendor/laravel/framework/src/Illuminate/Config/EnvironmentVariables.php on line 35
{"error":{"type":"ErrorException","message":"Undefined index: DB_HOSTNAME","file":"\/home\/martin\/code\/www\/pc_backend\/app\/config\/database.php","line":57}}
This is only on my local development system, where I recently installed apache and php. On my production system on a shared host artisan commands work just fine. The prod system has it's own .env.php, but other than that the code should be identical.
Relevant files:
.env.local.php
<?
return array(
'DB_HOSTNAME' => 'localhost',
'DB_USERNAME' => 'root',
'DB_NAME' => 'pc_booking',
'DB_PASSWORD' => 'secret',
);
app/config/database.php
<?php
return array(
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => $_ENV['DB_HOSTNAME'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
'migrations' => 'migrations',
),
);
The $_ENV array is populated as expected on the website - the problem appears to be with artisan only.
So I finally figured out how to fix it.
It turns out that the file was not processed as a php file because I was using a short opening tag in the .env.local.php file. Using a normal opening tag solved it. I don't know why though, as short tags work fine elsewhere.

FuelPHP - php oil refine migrate PDO Error

I'm trying to setup my fuelphp on ubuntu12, nginx in a development environment.
Everything was working for me except when I try to do php oil refine migrate.
I was faced with the following error message:
Error - invalid data source name in COREPATH/classes/database/pdo/connection.php on line 94
My development/db.php:
return array(
'default' => array(
'connection' => array(
'dsn' => 'mysql:host=localhost;dbname=fuel_intro',
'username' => 'root',
'password' => '',
),
),
);
I searched the Internet and fuelphp docs, and still no luck.
Any help will be appreciated.
It seems you're doing database configuration incorrectly. It shouldn't be 'host:localhost', it should be like 'hostname'=>'localhost'. And please use mysql or PDO instead of mysql... (because mysql_* functions are deprecated.
It should be something like:
'default' => array(
'type' => 'mysqli',
'connection' => array(
'hostname' => 'localhost',
'port' => '3306',
'database' => 'fuel_db',
'username' => 'your_username',
'password' => 'y0uR_p#ssW0rd',
'persistent' => false,
'compress' => false,
),
'identifier' => '`',
'table_prefix' => '',
'charset' => 'utf8',
'enable_cache' => true,
'profiling' => false,
),
Take a look at:
http://fuelphp.com/docs/classes/database/introduction.html for further information.

Database mysql proxy error while connect with YII

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
),

cakePHP: Can't connect to MSSQL datasource

I can't connect to a mssql database server using theese settings.
I get this error:
Fatal error: Call to undefined method DboSource::connect() in /home/websites/CakeShare/cake/libs/model/datasources/dbo_source.php on line 143
do i have to do something with my server?
$this->db_data['test'] = array(
'driver' => 'mssql',
'persistent' => false,
'host' => 'test.test.com',
'login' => 'login',
'password' => 'pass',
'database' => 'testdb',
'prefix' => ''
);
in /app/config/core.php
you can set the debug level from 0 to 2, please change the error level to 2 and give the ouptut.

Categories