Drupal error and solution: Access denied for user in mysqli or mysql

I have been facing this peculiar problem in drupal. I was migrating a drupal site from one server to another and it stopped working, giving me the error ‘Access denied for user ‘some_user’@localhost (using password: YES)

It was strange since i had done everything correctly and from command line i could login into mysql server.

While i was browsing the file sites/default/settings.php my eye went into the following lines:

/*
* Note that the $db_url variable gets parsed using PHP's built-in
* URL parser (i.e. using the "parse_url()" function) so make sure
* not to confuse the parser. If your username, password
* or database name contain characters used to delineate
* $db_url parts, you can escape them via URI hex encodings:
*
*   : = %3a   / = %2f   @ = %40
*   + = %2b   ( = %28   ) = %29
*   ? = %3f   = = %3d   & = %26

I was a victim of highly unpropable circumastances! lol My password contained the sequence ‘%40’ which was being considered as the escape of character ‘@’ , so my password was interpreted wrong!

I guess that this error had to do with the php version. So in my first server (Gentoo PHP 5.2.6-pl7-gentoo) there was no problem but in the second server (Debian – PHP 5.2.0-8+etch15) there was.

After i changed my password it connected successfully.

PS. It was over a year since i posted last time, so … hurray!

Rails select tag problem , not working , it doesn’t choose correct option in enum fields!

I have been searching for hours to solve a problem in one of my forms. One of my models has an enum field with some options. e.g. enum(‘a’, ‘b’, ‘c’)

When i edited an entry of this model class i noticed that my listbox didn’t have the correct option chosen.

e.g.

<%=  select('myobject', 'type', ["a","b","c"]) %>

didn’t work

<%=  select('myobject', 'type', ["a","b","c"], {:selected => @myobject.type}) %>

didn’t work either

After many hours and having to develop a helper select function of my own, i found out that this works:

<%=  select('myobject', 'type', ["a","b","c"], {:selected => @myobject.type.to_s}) %>

For some reason rails doesn’t recognize the enum field’s value as a string and the comparisons don’t take place correctly. After casting it to string it worked 🙂

That’s all for now. Bye.

WordPress – tinyMCE is not defined error, a solution

After spending lots of time for this tinyMCE bug and trying many solutions i found out there, i finally got it working. It seems to be a problem with gzipping tinyMCE code and some servers hosting wordpress.

I solved my problem on this server by editing file : wp-includes\js\tinymce\tiny_mce_config.php , line 208 in wordpress 2.5.1

Just change:

 'compress' => true

to

'compress' => false

Bugfixing for gWidgets for use with prototype 1.6.0.2

gWidgets is a really nice library of widgets. I have been using it for some time with success, gTabs especially.

A friend of mine ktolis who has been using the new Safari browser and Firefox 3 beta told me that the tabs wouldn’t appear because of javascript errors.

It has been concluded now that the errors were caused by 2 factors Firefox3 and Safari (that both implement HTML 5) and the fact i have been using latest prototype 1.6.0.2 library

Javascript errors appeared in lines 232, 299, 448 and 528 of gwidgets.js saying that ‘each is not a function’.

Then i found this post: document.getElementsByClassName

According to the above post in new browsers, implementing html 5, ‘each’ is not implemented on the array returned by document.getElementsByClassName() because getElementsByClassName is implemented by the browser and not prototype any more(for prototype 1.6 and newer that is). So i simply replaced document.getElementsByClassName(blahblah).each occurencies in gwidgets.js with for loops to iterate the returned array. The errors stoped after this.

Also i would like to mention another fix concerning a css problem with gTabs , where if the text inside the tab is quite large the tab doesn’t resize. If you comment line 95 in gwidgets.css the tabs can be resized to fit their content.

Cheers

Ruby Rails: Ajax is not defined error …

This has been a little tricky. I have followed a nice Ajax tutorial for rails but i kept getting the “Ajax is not defined” error in the javascript console. The solution is to include the prototype.js javascript file into your code. Simply write the following into your rhtml file:

 <%= javascript_include_tag "prototype" %>

That’s all.

Firebolt 0.3 released

Well at last firebolt 0.3 is released. If you are into C++ , sockets and of course protocols you have to take a look at it.

Firebolt is a network protocol oriented library. It’s not another socket library, it offers higher level services to the developer. You can structure your protocol in the form of states and the transitions between those states with the use of your custom events. Thus you no longer need to worry about what data you just received from a socket and whether or not those data are expected in the current state of your network code. That sort of validation is all performed by firebolt!

Enjoy!

Ruby Rails: How to add numeric pagination.

Perhaps you are still using the default rails pagination which appears as two links at the bottom of your page ‘Previous page’ and ‘Next page’. If you would like to alter this and be able to access any page instantly you could add the following code into your list.rhtml file:

< %
#here we add the code for enumeration of all available pages
numpage = 1
for a_page in @cert_incident_pages
if a_page == @cert_incident_pages.current
% >
< %= link_to '['+numpage.to_s+']', { :page => a_page } %>
< % else %>
< %= link_to numpage.to_s, { :page => a_page } %>
< %
end
numpage = numpage + 1
end
%>

Don’t forget to change the ‘@person_pages’ to correspond to your variable which is defined in your controller’s list method. Of course you can now remove the ‘link_to’ lines that render ‘Previous page’ and ‘Next page’.

That’s all for now and stay tuned for more code snippets and of course the new release of Firebolt.

Ruby rails: How to render an action and pass parameters to it

The problem is that some things are obvious and others simply seem obvious. Recently i was trying to alter a controller’s create action. By default if creation of the model fails the following code is executed:

render :action => ‘new’

The extra functionality i wanted was to pass the parameter :id into the above action. So i wrote this:

render :action => ‘new’, :id => myvalue

The problem to the above is that params[:id] didn’t get myvalue. After noumerous attempts and no luck searching the internet i came up with the solution.

params[:id] = myvalue

render :action => ‘new’

Trying to rationalize why the above code worked, i came to the conclusion that what ‘render’ does is simply to render the new.rhtml file and not execute the ‘new’ action from scratch. So the code contained in new.rhtml is executed in the context of the ‘create’ method of your controller. It is reasonable then to initialize params[:id] in ‘create’ method and then use its value in new.rhtml.

If the above reasoning is false in any way let me know.
By for now and keep coding. 🙂

Ruby rails: Tutorials about file uploading/downloading in/from a MySQL DB

Check the following 2 links. They have been really helpfull in my effort to add in a ruby rails application the ability to upload any kind of file to a MySql database. In addition downloading has also been rewarding.

Uploading files with Ruby rails in MySql DB
Downloading files with Ruby rails from MySql DB

Note the following problems i came across. In the rhtml file where the uploading form was, i tried to add

:multipart => true in the start_form_tag of this form. Yet it gave bogus html code for some odd reason, i had to comment it out and write the form tag by hand… By the way i use rails 1.0.0

That’s all for now.

Bye and keep coding.