Pages - Menu

Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Monday, January 28, 2013

Testing different database connections

Hello world!

I had to test some database connections from inside my application.

The user fill a form with the required information but before saving it to my PostgreSQL instance I had to check if everything is OK.

I was trying to use my model like this:


And guess what, as expected it replaces my application connection.

The solution is pretty simple, use the adapter class like:


The reason for this code be inside a bedin/rescue is that if anything is wrong with the connection data it will return 500 Internal Server Error

Problem solved.

Thursday, October 11, 2012

Rails - Can't convert fixnum to string during rake db:create

Hi fellas!

I'm using MySQL and tried to run rake db:create and this error was returned:

`connect': can't convert Fixnum into String (TypeError)


The problem is that YAML parser is trying to guess what data type value I have in my datase.yml.

My file was like this:

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: walk_benchmark_development
pool: 5
username: root
password: 123
socket: /var/run/mysqld/mysqld.sock


So the parser probably considers my password as a integer and forcing it to interpret my password as a string works.

password: "123"

Monday, October 8, 2012

MySQL - Error trying to install gem

Hi fellas!

Installing mysql gem I got this:

Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.

Which is a well known error for ruby users. It's all about lack of developer libraries.

To solve it I had to:

$ apt-get install libmysqlclient-dev



Adios!