Yii error using migration tool - php

I'm trying to use the migration tool, but am getting the following error:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused' in /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php:382
Stack trace:
#0 /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php(330): CDbConnection->open()
#1 /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php(308): CDbConnection->setActive(true)
#2 /Applications/MAMP/htdocs/yii-sandbox/framework/base/CModule.php(387): CDbConnection->init()
#3 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(442): CModule->getComponent('db')
#4 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(451): MigrateCommand->getDbConnection()
#5 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(482): MigrateCommand->getMigrationHistory(-1)
#6 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(84): MigrateCommand->getNewMigrations()
#7 [internal function]: MigrateCommand->actionUp(Array)
#8 /Applications/MAMP/htdocs/yii-sandbox/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(MigrateCommand), Array)
#9 /Applications/MAMP/htdocs/yii-sandbox/framework/console/CConsoleCommandRunner.php(71): CConsoleCommand->run(Array)
#10 /Applications/MAMP/htdocs/yii-sandbox/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)
#11 /Applications/MAMP/htdocs/yii-sandbox/framework/base/CApplication.php(180): CConsoleApplication->processRequest()
#12 /Applications/MAMP/htdocs/yii-sandbox/framework/yiic.php(33): CApplication->run()
#13 /Applications/MAMP/htdocs/yii-sandbox/projects/trackstar/protected/yiic.php(7): require_once('/Applications/M...')
#14 /Applications/MAMP/htdocs/yii-sandbox/projects/trackstar/protected/yiic(4): require_once('/Applications/M...')
I have checked the DB settings in console.php, which are as follows:
'db'=>array(
'connectionString' => 'mysql:host=127.0.0.1;dbname=yii_trackstar, unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',
'emulatePrepare' => true,
'username' => 'yii',
'password' => 'xxx',
'charset' => 'utf8',
),
As you can see, I've tried setting the host to 127.0.0.1 and setting the unix socket as per other suggestions.
I'm using MAMP (as you can see). from the protected dir, I'm running the command: ./yiic migrate
No matter what I change, I get the same error message.
*Update: *
I've just realized something. Changing the host=localhost to host=127.0.0.1 actually gives me a different error of connection refused. If I set that back to localhost the error is as follows:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory' in /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php:382

You can check the yii framework forum, there is already similar question posted at http://www.yiiframework.com/forum/index.php/topic/16-db-connection-string
NOTE
Specifically, what solved it is this from that thread:
A note on PHP and Mac OSX:
A version of PHP4 comes bundled on Mac OSX and is typically what is executed when you try the php command from the command line. You need to have the php command execute a version of PHP5.x or higher. Usually, you have already installed a version of PHP5.x or higher, but need to tell the php command to execute the newer version rather than the older one. There are certainly many ways to achieve this, but here is one:
At any terminal prompt, type in:
prompt>which php
this should tell you where the OS is looking for the php command tells me /usr/bin/php.
If I navigate to /usr/bin and issue an ls *php* I will see three files:
php
php-config
phpize
These are all for the bundled version PHP4.x
Rename these files to use a 4 in their names, to remember these are the executables for PHP4
mv php php4
mv php-config php-config4
mv phpize phpize4
Then, create sym links for each of these these to point to the PHP5.x or higher version you have installed. In my case these are located in /usr/local/apache/php/bin. So I would issue from the /usr/bin directory
ln -s [absolute path to your php5.x] php
and similarly for the other files.

While running yyic I've got problems until I've changed localhost to 127.0.0.1 in the connection string.

Try specifying the port in the host string. So localhost:8889 instead of just localhost or 127.0.0.1 — whichever you use.
This fixed my issue.

You can try setting the unix_socket with the correct keyword Socket and in the same way as the other vars in the string with ; and no spaces:
'connectionString' => 'mysql:host=localhost;dbname=yii_trackstar;Socket=/Applications/MAMP/tmp/mysql/mysql.sock',
You can check more connection strings over here: http://www.connectionstrings.com/mysql

Try setting host=127.0.0.1 on your db.php file

Simple Solution:
Just open the  mail-local.php  page inside  backend/common/config  directory. Then change localhost to 127.0.0.1 .
Now you run php yii migrate .
Hope, It will successfully create the tables in Databse

change connection string to this
'connectionString' => 'mysql:host=localhost;dbname=yii_trackstar',

Open your terminal and use this
echo "export PATH=/Applications/MAMP/bin/php/php5.x.x/bin:$PATH" >> ~/.profile
5.x.x is your version of PHP you use
This is because Yii framework use your default PHP come with OSX, not the PHP of MAMP.
To make sure, type "which php" to see if it's /Applications/MAMP/bin/php/php5.x.x/bin/php then you are done.
Hope this help :)

It's a mac problem where it uses an older version of php that is installed on the machine as opposed to the php5 that comes with MAMP. So I had to force it to use PHP version 5 that comes with MAMP.
So I had to write this in the Terminal and it worked:
/Applications/MAMP/bin/php/php5.5.3/bin/php /Applications/MAMP/htdocs/projectname/protected/yiic migrate

Edit file config/db.php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=namedb',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
];

MAMP PRO click Enable Allow access to MySql at Mysql Menu.

Related

Use odbc eloquent outside laravel PHP7

I am using eloquent outside laravel. I have my own PHP application.
This is what i am using https://github.com/illuminate/database
My config is as following
$settings3 = array(
'driver' => 'odbc',
'dsn' => "Driver={SQL Server};Server={serverName};Trusted_Connection=true;Database=telesur_mis;",
'username' => 'user',
'password' => 'user',);
$capsule->addConnection($settings3,'teleappframework');
After executing this code I am getting the following error
Fatal error: Uncaught InvalidArgumentException: Unsupported driver [odbc]
I have PDO ODBC installed, i have also tested pdo odbc connection outside of eloquent.
The reason for using ODBC is, because i am using PHP7 and currently there is no PDO extension for SQL Server.
Can anyone help me on this?
i would download FreeTDS and just use the regular sqlsrvr driver it works like a charm (if you are on a unix env) there is a lot of posts on how to configure it etc just look it up.
PHP7 has a few modules disabled by default that were previously enabled in PHP5.
Most likely running php -m does not show the modules you need.
It's an easy fix though since the extension should already exist in the \ext\ folder that came with PHP7. You just need to modify your php.ini file to include the line:
extension=php_pdo_odbc.dll
extension=php_odbc.dll
Then from a command prompt or terminal test again using php -m to see that the module is now listed.

Magento Cron Job fails while DLO not loaded

I am trying to run the Magento Cron job but get this error message. I checked phpinfo() which shows everything should be loaded and the get_loaded_extensions() shows => PDO [27] => pdo_mysql [28] => pdo_sqlite [29]
Any thoughts what I can do next to find the cause?
Thanks,
Chris
PHP Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with
message 'The PDO extension is required for this adapter but the extension is
not loaded' in /home/k117235a/domains/greenman-chris.eu/private_html/lib/Zend/Db/Adapter/Pdo/Abstract.php:342
Stack trace:
#0 /home/k117235a/domains/greenman-chris.eu/private_html/lib/Zend/Db/Adapter/Abstract.php(248):
Zend_Db_Adapter_Pdo_Abstract->setFetchMode(2)
#1 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource.php(175):
Zend_Db_Adapter_Abstract->__construct(Array)
#2 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource.php(110):
Mage_Core_Model_Resource->_newConnection('pdo_mysql', Object(Mage_Core_Model_Config_Element))
#3 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(320):
Mage_Core_Model_Resource->getConnection('core_write')
#4 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract
in /home/k117235a/domains/greenman-chris.eu/private_html/lib/Zend/Db/Adapter/Pdo/Abstract.php
on line 342
Probably you are checking the phpinfo() from the browser, but the extension might be loaded just for apache/nginx, and not for commandline, which is how I'm assuming the cronjob php file will run.
Check that the extension is enabled for CLI, typically in the following location:
/etc/php5/cli/conf.d/20-pdo_mysql.ini (the name might not be exactly the same)
It might be only on /etc/php5/apache2/ or /etc/php5/php-fpm/
You can just copy it from the other locations or create a new file with the following content:
extension=pdo_mysql.so
After that check that the extension is loaded by running from command-line:
php -i | grep pdo
If it's loaded you should see some output and the cronjob should now work.
I hope it helps.
Use "$ which php" to ensure you're using the PHP you think you are.
Look at the php.ini your command line PHP is using and see if any extensions are disabled
An alternate method is to have Apache run the cron jobs by using wget:
[specified time] wget -q http://magento.url.com/cron.php
Using this method also helps in cases where file permissions are an issue (specially when Magento's cache is involved).

Connect Laravel on ubuntu to Azure SQL Server

I am developing an laravel app using ubuntu as OS and my database is in a remote Azure Server.
After long a research I'm about to give up. Installed freetds, php5-sybase etc etc.
here is my connection file: (the default is set to sqlsrv)
....
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'myhostname:myport',
'database' => 'mydatabasename',
'username' => 'myusername',
'password' => 'mypassword'
),
....
and the error that I am getting is this one:
PDOException
SQLSTATE[01002] Adaptive Server connection failed (severity 9)
Any sugestions? If you guys need more details please ask :)
Thanks in advance
I solved my problem. It was missing #domain in my query string example:
$pdo = new PDO("dblib:host=xxxx:1433;dbname=yyyy", 'username#domain', 'password');
I get solution in Read from the server failed when trying to connect to sql-azure from tsql
Edit /etc/freetds/freetds.conf file and use 8.0 TDS version.
If haven't this file install FreeTDS with
sudo apt-get install freetds-bin
Check these:
port separator is "," on windows and ":" on linux/Mac. Since you have 1433, the default one, it is better probably not to use it at all
definitely test first from command line using one of these :
$ tsql -S sectionNameInFreetdsconf -U user -P pass
$ tsql -H hostname -p port -U user -P pass
locate freetds.conf on your disk. It is possible it exists in several places and tsql uses one while PHP used another one. Best is to symlink them into one common file and test on that. Note that a common place for that file is ~/.freetds.conf beside /etc/ or /usr/local/etc/
there should be a [global] section on your freetds.conf file. Put there these lines :
tds version = 8.0
text size = 20971520
client charset = UTF-8

Error installing Recess PHP framework

I downloaded the Recess PHP Framework source and untar in /var/www/html.
I did the modification as per readme in recess-conf.php.
{
RecessConf::$defaultDatabase
= array( //'sqlite:' . $_ENV['dir.bootstrap'] . 'data/sqlite/default.db'
'mysql:host=localhost;dbname=testdb', 'root', 'root'
);
}
I am getting the error when I open the google-chrome and type localhost
PDO has not been imported.
Location: Line 19 of /var/www/html/recess/recess/database/pdo/PdoDataSource.class.php
followed by call stack.
Please let me know how to resolve the issue.
Regards
Sachin
var_dump(extension_loaded ('pdo_mysql'));
Check pdo_mysql is loaded or not.

cake console 2.2.1: Bake errors

OSX machine running MAMP. CakePHP 2.2.1 installed and configured properly (meaning that I have all green bars when I browse to the Index.php file, I have completed the Blogs tutorial and am working on my second app with which scaffolding is up and running). Now I am trying to Bake for the first time.
Per the cookbook (and others), I installed a fresh copy of cake into a directory (my users directory) and then put the path variable in my .bash_profile file
export PATH="$PATH:/Users/p_scott/cake221/app/Console"
after which I was able to go into Terminal, type cake and have the console come up. You can see that up to that point, I was invoking the console from the app directory.
I first tried running cake bake from the terminal using the -app parameter and designating the path to my practice apps. The first time I did this, I got the following
Welcome to CakePHP v2.2.1 Console
-------------
App : app
Path: /Applications/MAMP/htdocs/blog/app/
-------------
Interactive Bake Shell
---------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)
> c
--------------------
Bake Controller
Path: /Applications/MAMP/htdocs/blog/app/Controller/
--------------------
\Use Database Config: (default/test)
[default] >
No matter what I put in for the database (if I leave it blank, it asks me again), but any answer gives me the following error:
Warning Error: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in [/Users/p_scott/cake221/lib/Cake/Model/Datasource/Database/Mysql.php, line 149]
Error: Database connection "SQLSTATE[HY000] [2002] No such file or directory" is missing, or could not be created.
#0 /Users/p_scott/cake221/lib/Cake/Model/Datasource/DboSource.php(260): Mysql->connect()
#1 /Users/p_scott/cake221/lib/Cake/Model/ConnectionManager.php(101): DboSource->__construct(Array)
#2 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ModelTask.php(906): ConnectionManager::getDataSource('default')
#3 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(396): ModelTask->getAllTables('default')
#4 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(419): ControllerTask->listAll(NULL)
#5 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(136): ControllerTask->getName()
#6 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(61): ControllerTask->_interactive()
#7 /Users/p_scott/cake221/lib/Cake/Console/Command/BakeShell.php(113): ControllerTask->execute()
#8 /Users/p_scott/cake221/lib/Cake/Console/Shell.php(393): BakeShell->main()
#9 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php(201): Shell->runCommand(NULL, Array)
#10 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
#11 /Users/p_scott/cake221/app/Console/cake.php(33): ShellDispatcher::run(Array)
#12 {main}
Once I started getting this error, I tried navigating in terminal to the <cake install dir>/app/Console folder and the <different instance of cake install dir>/app/Console folder to try the console from within my app/s. I either get the same errors or it asks me different questions, like:
What is the path to the project you want to bake?
[/Users/p_scott/myapp] > /Applications/MAMP/htdocs/history/app
What is the path to the directory layout you wish to copy?
[/Applications/MAMP/htdocs/history/lib/Cake/Console/Templates/skel] >
PHP CLI is installed and it appears to be working
PHP 5.3.8 (cli) (built: Dec 5 2011 21:24:09)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
My PDO support appears to be enabled. In terminal I typed:
php --ri pdo
PDO
PDO support => enabled
PDO drivers => mysql, sqlite, sqlite2
I don't have a php.ini file in Apache (because I am on a Mac), but the one in the PHP 5.36 directory, I have the following extensions enabled:
extension=imap.so
extension=yaz.so
extension=mcrypt.so
extension=gettext.so
extension=pgsql.so
extension=pdo_pgsql.so
extension=pdo_mysql.so
After taking a break, I found an article
(http://www.dereuromark.de/2011/10/31/freshly-baked-cake2-0-tips/) that talks about a change of console location in 2.0. I should try using it from that location (<cake installed dir>/lib/Cake/Console ). Once I tried this, I either got the questions about what layout I wanted to use or... ONCE, I was able to get the bake application to ask me to create a database configuration. I went through the steps and it pooped out this error at the end:
Fatal error: Class 'DATABASE_CONFIG' not found in /Applications/MAMP/htdocs/history/lib/Cake/Console/Command/Task/DbConfigTask.php on line 264
Which leads me to one more piece of info. This is my default DB configuration in the <cake installation dir>/history/app/Config/database.php file.
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakeHistoryUser',
'password' => 'cakeHistoryPassword',
'database' => 'cake_history',
'prefix' => '',
//'encoding' => 'utf8',
);
Before posting this question (and all of this information), I spend some quality time out here and it seems like most of my issues are or CLI related but I just don't see where I need to change something and hours and hours later, I need some help.
Help me Obi Wan, you are my only hope
The problem is you are trying to interact with the database via the command line, however the PHP-CLI is a different install than the one proveided by MAMP so it doesn't know about the database server.
Try changing localhost to 127.0.0.1 in your app/Config/database.php file and that should do the trick.
Something like this happened to me, and the easiest way I found to make it work which I don't see here is changing localhost to 127.0.0.1 and adding the port number at the end, e.g., MAMP uses port number 8899, so:
"mysql:host=127.0.0.1:8889"

Categories