How To Specify An AUTO_INCREMENT Value in MySQL

I needed to reset the value of an auto_increment number after doing a bunch of tests in a MySQL database. I just wanted the number to be more accurate & reflect more closely the number of actual items in the database, since every deletion just leaves a "hole", as the incremented value doesn't reset after a delete.

This is a real quick solution, so here goes:

Problem
I've deleted a bunch of items in a database with an auto_increment field in one of the tables. (In my case, I did a ton of testing with importing/creating new posts on a Drupal site, and deleted them all to start fresh with the "real" content. In Drupal, new nodes just keep incrementing after those deletions, so my node values where way off... I wanted to align them more correctly with the new "real" import.)

Solution
Run a simple SQL command on the particular table with the auto_increment to set the value where you want it.

ALTER TABLE this_is_the_table AUTO_INCREMENT = 100;

That's it! I won't go into specific Drupal issues with doing this on the 'nid' field of your nodes table, but mainly, you should be careful to make this new value higher than the number of nodes you currently have in the database.

It's possible that ALTER will actually count the rows in the table and just +1 the value if you have fewer than the number you're asking for. IE: you have 110 rows already, but run the above command... I think it will just set the auto_increment value to 111, instead of failing. (Do your own research on that, though... I'm too lazy right now to do it for you. :P )

Cheers!

(BTW, how do you like the ultra-spiffy new code highlighting??!? Awesome how it sets up links to research the keywords, I thought. I'm going to have fun with that puppy. :)

Drupal FeedAPI & Feed Element Mapper Missing Unnamed Elements In Array

I really need to figure out how to title some of these things! It's quite hard to find a way to make a title, when the posts are so varied! The title seems to need being both a summary and a brief title.. bad combo.

Aaanyway... Quick problem I've been having that cost me many days of headaches. I'm hoping this will help others as well as remind me later what the problem was and how to solve it.

Basically, I'm using the FeedAPI and Feed Element Mapper in Drupal to import some data feeds and create content nodes for display in one of my sites. The thing is, my data feed is not simple RSS formatted, so it includes a bunch of other XML elements that all the parsers coming with FeedAPI are missing! Argh! I figured out a way to expose a bunch of the elements that were getting missed... but be warned, it's a bit of a hack job.

(This is a solution for people already working with FeedAPI/FEM and isn't a tutorial on the usage of either of those... sorry.)

Read more for the rest...

Installing Zend Framework on Cpanel Server

Another quickie for those of you wanting to install the Zend Framework on your Cpanel-powered Web servers.

I'm doing a bunch of updating to another set of Web sites I run (ahem OnlineGameHounds.com... PointlessGames.com, etc. cough) and needed to try out some modules that needed the Zend Framework. I'm not going to go into what that is (read for yourself, please) or why I need it (seriously, I need to get back to that work instead of writing this post! I shouldn't even be here at the bar with you blokes, I've got work to do!). If you need to know how to do this solution, you're likely only reading this because you're searching around for it on the Grand Googly-Moogly, et. al.

If you don't know what this stuff is, well... you're awful bored to be reading around on random posts about words like "Zend" that just look funny, aren't you??!? (Well, you're welcome here, for sure! Look around! :)

Hit the "read more"-type link to get at the problem/solution pair for this thing...

Linux: Listing the number of files in a directory

Here's a quickie, but it was useful for something I was messing with: In Linux (or Unix, etc.), how do you list the number of items in a directory from the command line?

This Worked:
I'll admit up-front that this is a bit of a hack (in my opinion), but it works fine for simply finding out how many items are in a directory. The reason it's a hack is explained below.

This is a simple command option using the "ls" and "wc" commands in tandem. Here's what you run (from inside the directory you're interested in):
ls -l | wc -l

Briefly, that's the list command "ls" with the -l option, which gives a verbose list option to the command. This is combined with the "wc" (short for "word count") command, which displays a count of lines (the "-l" option in this case), words and characters in a file... yeah, a file, but we're interested in counting items in a directory, right? Well, that's the whole "|" bit, which is called "piping" -- executing commands in a sequence.

What we're saying with this command is roughly: "get a list of the contents in this directory, but show me a count of the lines in the list"... like I said, that's roughly what it means. I'll leave it to you to do more research to learn more about these commands and their options.

I'm calling this is a bit of a hack only because you're getting a count of lines in the listing, which can include some unwanted bits in this case... like directories will show up as a line item, which you may not be interested in counting. Maybe you see the slight draw back here? For my needs, total accuracy wasn't important -- just a close estimate.

Some variations on the theme:

ls -Rl | wc -l
Give me a count of the number of items in the current directory and all subdirectories ("R" means to "recurse" into the directories in the list... neat.)

ls -l someDirectoryNameHere | wc -l
Give me the count for a specific directory.

Joomla Community Builder "cb.core" foreach bug fix

In the Joomla! CMS (which this site is not run on, incidentally, but I use at Flash Game Post), I was having trouble with the Community Builder component throwing an error. It's a simple fix to get around it in version 1.1 (currently, they have 1.2 RC4, but I don't have time to test software this month.)

Problem:
In Joomla 1.5, using Community Builder 1.1, when going into a user's profile page, this error was thrown:

Warning: Invalid argument supplied for foreach() in /components/com_comprofiler/plugin/user/plug_cbcore/cb.core.php on line 240

This Worked!:
This is a known bug in v1.1, so here's the known fix for it, presented in just one more place in case Google helps you come and visit me instead of someone else! :)

  1. Open the file ./components/com_comprofiler/plugin/user/plug_cbcore/cb.core.php with your favorite code editor. Change line 528 from this:
    $params =& $juser->getParameters();

    To this:
    $params =& $juser->getParameters(true);
    (yes, just add the word "true" in parenthesis.)

  2. Delete line #529, which is this:
    $params->loadSetupFile(JApplicationHelper::getPath( 'com_xml', 'com_users' ));

Tada! All fixed up... well, you need to save that file and re-upload it to the server, of course. You knew that, though... right?

Cheers.

WGET Shows "403: Forbidden" Error -- Apache 1.x Filesize Issue

Man, another one of these difficult-to-title posts! I can see this will be a recurring problem for me! :P

Problem:

I had a large backup file on one of my web servers that I wanted to transfer to another web server using WGET instead of doing the drastically-slower transfer to/from my office workstation through a DSL connection. In my situation, it appears that Apache 1.x doesn't support transferring large files >2GB in size, but Apache 2.x does. Using a simple WGET command like this:

wget http://www.domain-name-here.com/filename.tar.gz

rendered the "403: Forbidden" error. Trying to access this same file from a Web browser got me the same problem, which started pointing fingers in weird directions for the problem space. The file had proper permissions and should have been accessible... until I realized a simple "test.txt" file worked just fine. Hmmmm... it turns out this wasn't just permissions issues or such, but must be due to the Apache size limitation (or other such issue that doesn't matter, because I found a solution for my case...)

This Worked:

My solution was made easier since I have full control over both Web servers, but hopefully this helps people in a general sense anyway. Both servers run Red Had Linux Enterprise and Cpanel for the control panel. One server (the "source" of the file) is running Apache 1.x and the other ("destination") is Apache 2.2x... whether that would ultimately matter for this solution is likely a non-issue. I ended up going an FTP route instead of HTTP anyway, but you at least know the full picture FYI.

I don't have anonymous FTP turned on anywhere and didn't want to get into that, so I just created a new FTP account on the source server's cpanel account that had the big (7GB) backup tar file. From here, I was able to SSH into my destination server and run a simple WGET command to copy the file from one server to the other across the Intarweb:

Syndicate content