Welcome, Guest. Please login or register.
Did you miss your activation email?
Oct. 23, 2014, 10:17:32 PM
56628 Posts in 12745 Topics by 19531 Members
Latest Member: oHildredCakmak
News:
 
The PRADO Community » Prado v3.x » Tips, Snippets and Tutorials » TDbConnection: SQLSTATE[HY000] [2002] Connection Refused « previous next »
Pages: [1] Print
Author Topic: TDbConnection: SQLSTATE[HY000] [2002] Connection Refused  (Read 6084 times)
dswain
Junior Member
**

Karma: 0
Offline Offline

Posts: 5


View Profile
« on: Oct. 16, 2009, 03:58:09 PM »

Hello Everyone!

I'm pretty new to Prado, so sorry if I'm missing something incredibly obvious. I'm working on the Prada Blog Tutorial, and in particular, working on getting the Active Record portion of things working. I've created my database/tables, made sure I can login with the credentials I provide in the applications.xml file and configured my application.xml file as follows:

Code:
<?xml version="1.0" encoding="utf-8"?>

<application id="blog" mode="Debug">
    <paths>
        <using namespace="Application.database.*" />
    </paths>
   
    <!-- configurations for modules -->
    <modules>
        <module id="db" class="System.Data.TDataSourceConfig">
            <database ConnectionString="mysql:host=localhost:3306;dbname=website" Username="my_actual_username" Password="my_actual_pw" />
        </module>
       
        <module class="System.Data.ActiveRecord.TActiveRecordConfig" ConnectionID="db" />
    </modules>

    <!-- configuration for available services -->
    <services>
        <service id="page" class="TPageService" DefaultPage="Home">
            <pages MasterClass="Application.layout.MainLayout"/>
        </service>
    </services>
</application>

Attempting to generate the Active Record classes (UserRecord.php and PostRecord.php) using prado-cli.php, I created the database directory (as per the instructions) and I'm having some kind of connection issue. The error is as follows:

Code:
[dswain@peggyo blog]$ php ../prado/framework/prado-cli.php shell .
Command line tools for Prado 3.1.6.
** Loaded PRADO appplication in directory "protected".
PHP-Shell - Version 0.3.1, with readline() support
(c) 2006, Jan Kneschke <jan@kneschke.de>

>> use '?' to open the inline help

>> generate users Application.database.UserRecord
PHP Fatal error:  Uncaught exception 'TDbException' with message 'TDbConnection failed to establish DB connection: SQLSTATE[HY000] [2002] Connection refused' in /srv/http/prado/framework/Data/TDbConnection.php:180
Stack trace:
#0 /srv/http/prado/framework/Data/TDbConnection.php(153): TDbConnection->open()
#1 /srv/http/prado/framework/Data/Common/TDbMetaData.php(52): TDbConnection->setActive(true)
#2 /srv/http/prado/framework/Data/ActiveRecord/TActiveRecordGateway.php(113): TDbMetaData::getInstance(Object(TDbConnection))
#3 /srv/http/prado/framework/prado-cli.php(666): TActiveRecordGateway->getTableInfo(Object(TDbConnection), 'users')
#4 /srv/http/prado/framework/prado-cli.php(607): PradoCommandLineActiveRecordGen->generateActiveRecord(Object(TActiveRecordConfig), 'users', '/srv/http/blog/...')
#5 /srv/http/prado/framework/prado-cli.php(761): PradoCommandLineActiveRecordGen->performAction(Array)
#6 /srv/http/prado/framework/3rdParty/PhpShell/PHP/Shell.php(839): PHP_Shell_Extensions_ActiveRecord->generate('generate users ...')
# in /srv/http/prado/framework/Data/TDbConnection.php on line 180
[dswain@peggyo blog]$

I'm assuming that I've just made some kind of mistake with configuring the application.xml file, but I'm not seeing it. I'm using the following websites for my configurations:
http://pradosoft.com/demos/blog-tutorial/?page=Day2.CreateAR
http://pradosoft.com/wiki/index.php/Simple_database_authentication_tutorial_with_Prado_3.1.1

Any thoughts? Thanks a bunch!
Logged
dswain
Junior Member
**

Karma: 0
Offline Offline

Posts: 5


View Profile
« Reply #1 on: Oct. 16, 2009, 07:25:54 PM »

Oh, and sorry. Some other information I forgot:

Arch Linux (Latest Version)
PHP 5.3.0
MySQL 5.1.39
Apache 2.2.14
Prado 3.1.6.r2699
Logged
tof06
PRADO v3.x Developer
Platinum Member
*****

Karma: 94
Offline Offline

Posts: 1084



View Profile
« Reply #2 on: Oct. 17, 2009, 11:51:31 AM »

Connection refused usally means that the mysql server isn't running, or doesn't listen on the specified port.
Make sure the mysql process is running.
Because the db seems to be on localhost, you can try to remove the :3306 in the DSN. It will use the Unix socket instead of the TCP Port.
Logged
dswain
Junior Member
**

Karma: 0
Offline Offline

Posts: 5


View Profile
« Reply #3 on: Oct. 18, 2009, 12:32:07 AM »

Thanks tof06. I made sure to check out that mysqld is running, and it looks fine. I also make sure to check out the uptime of mysql when I try and run these commands (making sure it doesn't shutdown). I modified my application.xml like you said to make use of the UNIX Socket:

Code:
        <module id="db" class="System.Data.TDataSourceConfig">
            <database ConnectionString="mysql:host=localhost;dbname=website" Username="****" Password="*****" />
        </module>

The following happens when I attempt that:

Code:
>> generate posts Application.database.PostRecord
PHP Fatal error:  Uncaught exception 'TDbException' with message 'TDbConnection failed to establish DB connection: SQLSTATE[HY000] [2002] Invalid argument' in /srv/http/prado/framework/Data/TDbConnection.php:180
Stack trace:
#0 /srv/http/prado/framework/Data/TDbConnection.php(153): TDbConnection->open()
#1 /srv/http/prado/framework/Data/Common/TDbMetaData.php(52): TDbConnection->setActive(true)
#2 /srv/http/prado/framework/Data/ActiveRecord/TActiveRecordGateway.php(113): TDbMetaData::getInstance(Object(TDbConnection))
#3 /srv/http/prado/framework/prado-cli.php(666): TActiveRecordGateway->getTableInfo(Object(TDbConnection), 'posts')
#4 /srv/http/prado/framework/prado-cli.php(607): PradoCommandLineActiveRecordGen->generateActiveRecord(Object(TActiveRecordConfig), 'posts', '/srv/http/blog/...')
#5 /srv/http/prado/framework/prado-cli.php(761): PradoCommandLineActiveRecordGen->performAction(Array)
#6 /srv/http/prado/framework/3rdParty/PhpShell/PHP/Shell.php(839): PHP_Shell_Extensions_ActiveRecord->generate('generate posts ...')
#7  in /srv/http/prado/framework/Data/TDbConnection.php on line 180

I tried setting up a typical PDO query using just the PHP PDO class and got the same error from MySQL. I'll keep hunting/tinkering, but any other thoughts?
Logged
dswain
Junior Member
**

Karma: 0
Offline Offline

Posts: 5


View Profile
« Reply #4 on: Oct. 18, 2009, 12:53:07 AM »

Ah-Ha! I've seemed to resolve the issue by changing it back to the format you recommended and specifying where exactly the socket file is located. I find it kind of odd that I have to do that in DSN, but it did work, so I'm not complaining...

For those of you who might need this info, here's what my application.xml file looks like now:

Code:
<?xml version="1.0" encoding="utf-8"?>

<application id="blog" mode="Debug">
    <paths>
        <using namespace="Application.database.*" />
    </paths>
   
    <!-- configurations for modules -->
    <modules>
        <module id="db" class="System.Data.TDataSourceConfig">
            <database ConnectionString="mysql:host=localhost;dbname=website;unix_socket=/tmp/mysql.sock" username="****" password="****" />
        </module>
       
        <module class="System.Data.ActiveRecord.TActiveRecordConfig" ConnectionID="db" />
    </modules>

    <!-- configuration for available services -->
    <services>
        <service id="page" class="TPageService" DefaultPage="Home">
            <pages MasterClass="Application.layout.MainLayout"/>
        </service>
    </services>
</application>

I also had to set up the date_timezone value in my php.ini file, but that error came up after these. Thanks for the help!
Logged
Pages: [1] Print 
« previous next »
Jump to: