Posts Tagged php

How To Repair Your Database Using phpMyAdmin

When I first began to host my own blogs, learning about FTP and phpMyAdmin, I was extremely intimidated. But I am more comfortable tinkering in the database files, and have discovered how powerful the phpMyAdmin software truly is.

It is important, if you are going to be a blog owner hosting your websites on your own domains, that you learn how to manage your databases. A database is, simply, is a structured collection of data that is stored in a computer system. Your blog uses something called an “SQL database.” It is important to know how your databases are organized and how they work. This will greatly reduce the agonies and sufferings (and they are SURE to come) of database problems and other issues. In this post, I’m going to show you how to repair and optimize your databases using phpMyAdmin.

Older blogs with numerous posts and comments tend to show their age after time. Coding and other information gets scrambled or confused, or sometimes the server has to work very hard to locate specific files and such. It helps greatly to repair and optimize databases. This is especially helpful when your blog “goes down” (aka, crashes faster than compact flash) frequently for no good reason. Try repairing the database. It’s not hard; here’s how to go about it:

Log in to your web host’s cPanel using the username and password you made when starting the account. Once you are on the home page of your cPanel, scroll down to “Databases.” Look for “phpMyAdmin.” The screenshots are from my own account with Hostgator. Hostgator’s cPanel is much like Bluehost.

cPanelSCrnSht

So, once you choose phpMyAdmin, a new window (or tab) should appear. phpMyAdmin is an extremely powerful and useful software program that manages databases. Once you have accessed phpMyAdmin, you’ll see to the left a column listing your databases. I have six databases on this web host, so there are six in the column. (I scratched out the names to keep hackers at bay).

phpMyAdmin 1

Choose the database you want to work with by clicking on the name. When you do, a table will appear in the left-hand side and right-hand side of the software. The left-hand side shows the tables in your database in a list. The right-hand side shows them but also gives you a platform with which to work with the tables. We’re going to move our attention to the right-hand, wider side of the screen. Here’s a snippet of what you will see.

phpMyAdmin 2

These are the tables for your database to your blog. Some things may look familiar, like active plugins, comments on your blog, links, etc. We aren’t going to deal with individual files here– we are just going to repair all these files at once, and then optimize them. phpMyAdmin makes this easy.

You want to find the “Check All” feature, to select every table in the database. This feature is usually at the very bottom of the table. Click “Check All” and all the check boxes should show checkmarks in them.

phpMyAdmin 2

Now, go to the drop down menu at the bottom of the databse table. Choose “REPAIR.” (Note: in the screenshot below, there are no checkmarks in my boxes because I forgot to “Check All” when I was making the screenshot for this blog post. Your own checkboxes should all have checkmarks in them when you chose “REPAIR.”)

Repair

When you let go of the mouse, the repair process will commence immediately and the page will reload. Don’t worry if everything disappears for a moment. It will come back with this message:

phpMyAdmin 3

You can see the “repair” in the table above, and that everything went “OK.”

Now, go to the top of the database and look for “Structure.” This will take you back to the database table you saw right before you chose “REPAIR” from that drop-down menu. If you look in the above photo again, you’ll see “Structure” in the top left-hand area.

Once you are at the database table again, you want to “Check All” again. This time you are going to “OPTIMIZE” the database. This will organize the tables and information.

phpMyAdmin 2

(Note: in the screenshot below, there are no checkmarks in my boxes because I forgot to “Check All” when I was making the screenshot for this blog post. Your own checkboxes should all have checkmarks in them when you chose “OPTIMIZE.”)

Optimize

As with the “REPAIR” process, the page will reload and give you confirmation that the database has been optimized.

phpMyAdmin 4

That’s it! You can use the column in the left-hand side to go to your other databases and repair/optimize them as well. When you are done, you can log off of phpMyAdmin by choosing the green square that says “EXIT.” This will log you out and you can close this window (or tab).

phpMyAdmin 5

When you close out phpMyAdmin, you will notice that you are still in your cPanel. When you have finished things there (if you have anything else to do there), you can log off that, too.

Remember, it is helpful to repair and optimize your database  from time to time, as it gets older. I have seen some geeks recommend transferring very old blog data into a totally new database and archiving it. Maybe we’ll get to that some other time. :)

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: , , ,

WordPress: How To Make Sidebar Load Last

A big problem for me is using WordPress templates with the sidebars on the left side. Oftentimes, the left sidebar loads before the main content of my blogs. This is extremely annoying. If, for some reason, my buttons, badges, or blogrolls in my sidebar are taking too long (which usually happens), the main content will never load!

Here’s a little tweak I have learned to force the main content of the blog to load before the sidebar. Please be aware that NOT all themes are alike, so your experience may vary. ALWAYS BACK UP YOUR BLOG before changing the coding. You should always back up your blog, anyway! But if you are going to attempt to do my fix, please back it up. Rest assured, this fix is simple and quick and painless. But you should always back up your existing information, just in case.

Notice in your WordPress php files that you have varying files, like footer.php, index.php, single.php, and etc. My own theme had the basic php files without any extras. Some more complex themes may have additional php files to do the jobs that your theme requires. You may have to play everything by ear, here. The nice thing is that my fix does not delete anything or alter anything major: all it does is tell the computer what part of the theme to load first.

OK, enough of all the preliminaries. In my theme, these are the php files that we’re going to alter. We’ll go over them individually.

index.php
page.php
single.php

The index.php is the information for the “face” (or homepage) of your blog. It tells the blog how to operate and when. Open the file now. You’ll see a lot of coding. What concerns us is the “get header,” “get sidebar,” and “get footer” stuff at the very top and the very bottom. So at the top, you’ll see this:

<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id=”content”>

then you’ll see a lot of coding after that, and then at the bottom of the file, you’ll see this:

<?php endif; ?>
</div>
<?php get_footer();?>

These two sections are telling the computer to load the main homepage of your blog in this order:

1. Header
2. Sidebar
3. Content
4. Footer

We want to change that. We want to switch the “Sidebar” and “Content.” And that is what you do. Copy this section in that file, that says:

<?php get_sidebar(); ?>

and then delete it. Now, scroll down to the bottom of the file. See where the file says:

</div>
<?php get_footer();?>

Place your copied “get sidebar” code right before the “get footer” code. You may have to make a new line (by pressing ENTER on your keyboard) if there is no space. I did have to.

So now, the very top of this index.php file says:

<?php get_header(); ?>

<div id=”content”>

And the very bottom of it now says:

</div>
<?php get_sidebar(); ?>
<?php get_footer();?>

Save the document and upload it to your FTP or, if you are working within WordPress in your browser, press SAVE.

You have to go back and do this same thing for each of the other php files I listed: the single.php, page.php. Some themes have archives.php, and different templates for different Pages on their blogs. If so, just go through those and do the same thing. This will make the loading of your blog consistent, whether people visit your homepage, a single post, an archived post, or a page post.

When you are done and everything is saved, your blog should now load in this order:

1. Header
2. Content
3. Sidebar
4. Footer

Remember, if you find that you don’t like the fix, or something goes screwy, you can always revert back to what you have as your back up. You DID back up your blog, right?

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: , ,

Secret Key for WordPress Blogs

I’ve been hearing that some blogs are getting “hacked.” I’m still in the process os understanding how a blog can be hacked (there are numerous ways). I think it is a heinous thing to do, but the perpetrators always get away with it. As I dig deeper into the WordPress forums (about as exciting as perusing a life insurance quote), I’ll be sure to let you know what I discover.

I did find this handy little tip: set up a Secret Key for your WordPress blog. If you are computer-challeneged, this might be something you’d want to skip or get help with. You DO NOT want to go tinkering around with your php files if you don’t know what you’re doing!! But for those of you who are experienced, this may prove a worthy exercise.

Like I said, I’ll be posting more about all these things in days to come. Until then– blog safely and BACK UP YOUR BLOG on a regular basis!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: ,