Friday, December 19, 2014

FuelPHP MAMP Pro db.php

I recently encountered an error in FuelPHP white migrating my scaffolding...

using php oil r migrate


THE PROBLEM
Uncaught exception Fuel\Core\Database_Exception: SQLSTATE[HY000] [2002] No such file or directoryCallstack: #0 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/database/pdo/connection.php(191): Fuel\Core\Database_PDO_Connection->connect()#1 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/database/query.php(287): Fuel\Core\Database_PDO_Connection->query(1, 'SELECT * FROM `...', false)#2 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/dbutil.php(621): Fuel\Core\Database_Query->execute(NULL)#3 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/migrate.php(595): Fuel\Core\DBUtil::table_exists('migration')#4 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/migrate.php(74): Fuel\Core\Migrate::table_version_check()#5 [internal function]: Fuel\Core\Migrate::_init()#6 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/autoloader.php(375): call_user_func('Migrate::_init')#7 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/autoloader.php(249): Fuel\Core\Autoloader::init_class('Migrate')#8 [internal function]: Fuel\Core\Autoloader::load('Migrate')#9 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/tasks/migrate.php(223): spl_autoload_call('Migrate')#10 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/tasks/migrate.php(151): Fuel\Tasks\Migrate::_run('default', 'app')#11 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/base.php(457): Fuel\Tasks\Migrate->__call('run', Array)#12 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/base.php(457): Fuel\Tasks\Migrate->run()#13 /Users/chriscubos/OneDrive/www/templates/admin/fuel/packages/oil/classes/refine.php(106): call_fuel_func_array(Array, Array)#14 [internal function]: Oil\Refine::run('migrate', Array)#15 /Users/chriscubos/OneDrive/www/templates/admin/fuel/packages/oil/classes/command.php(125): call_user_func('Oil\\Refine::run', 'migrate', Array)#16 /Users/chriscubos/OneDrive/www/templates/admin/oil(57): Oil\Command::init(Array)#17 {main}
Previous exception: Uncaught exception PDOException: SQLSTATE[HY000] [2002] No such file or directoryCallstack: #0 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/database/pdo/connection.php(96): PDO->__construct('mysql:host=loca...', 'root', 'root', Array)#1 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/database/pdo/connection.php(191): Fuel\Core\Database_PDO_Connection->connect()#2 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/database/query.php(287): Fuel\Core\Database_PDO_Connection->query(1, 'SELECT * FROM `...', false)#3 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/dbutil.php(621): Fuel\Core\Database_Query->execute(NULL)#4 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/migrate.php(595): Fuel\Core\DBUtil::table_exists('migration')#5 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/migrate.php(74): Fuel\Core\Migrate::table_version_check()#6 [internal function]: Fuel\Core\Migrate::_init()#7 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/autoloader.php(375): call_user_func('Migrate::_init')#8 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/classes/autoloader.php(249): Fuel\Core\Autoloader::init_class('Migrate')#9 [internal function]: Fuel\Core\Autoloader::load('Migrate')#10 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/tasks/migrate.php(223): spl_autoload_call('Migrate')#11 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/tasks/migrate.php(151): Fuel\Tasks\Migrate::_run('default', 'app')#12 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/base.php(457): Fuel\Tasks\Migrate->__call('run', Array)#13 /Users/chriscubos/OneDrive/www/templates/admin/fuel/core/base.php(457): Fuel\Tasks\Migrate->run()#14 /Users/chriscubos/OneDrive/www/templates/admin/fuel/packages/oil/classes/refine.php(106): call_fuel_func_array(Array, Array)#15 [internal function]: Oil\Refine::run('migrate', Array)#16 /Users/chriscubos/OneDrive/www/templates/admin/fuel/packages/oil/classes/command.php(125): call_user_func('Oil\\Refine::run', 'migrate', Array)#17 /Users/chriscubos/OneDrive/www/templates/admin/oil(57): Oil\Command::init(Array)#18 {main}




Been searching the web but hard to find the solution even from the FuelPHP forum. However, I finally figured it out and was able to make it run nicely





Christophers-MacBook-Pro:fuelphp chriscubos$ php oil r migrate
Performed migrations for app:default:
001_create_users
Christophers-MacBook-Pro:fuelphp chriscubos$ 


Finally got it to work on a MacOSX Yosemite Operating System Running MAMP Pro 3.0.5


THE SOLUTION #1






return array(
'default' => array(
'connection'  =>array(
'dsn' => 'mysql:host=localhost;dbname=fuelphp;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',
'username'   => 'root',
'password'   => 'root',
),
),
);



JUST ADD

;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',



ANOTHER SOLUTION THAT WAS ALSO PROPOSED ON STACK OVERFLOW BUT DIDN'T WORK ON ME WAS TO CHANGE localhost to 127.0.0.1





I hope this works for you ...


#fuelphp #orm #PDO #MAMP #MAMPPro #UNIX_SOCKET #PHP #MySQL #UncaughtException


Christopher John Cubos
Founder




NOTE: I'm using OneDrive to sync with all my computers instead of Dropbox due to sync problems.

You may download it here .. I'm 70% onto my referral so any signups will help

NOTE: This will also work with Yii Framework problems.

Change localhost to 127.0.0.1 in your connection string.

'dsn' => 'mysql:host=127.0.0.1;dbname=fuelphp',

OR:

Add unix_socket=/path/to/socket in your connection string.

'dsn' =>  'mysql:host=localhost;dbname=fuelphp;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',


https://onedrive.live.com/?invref=f834dec628b86abb&invsrc=90