Upgrading to MySQL 5 from MySQL 4
Posted in MySQL Database Stuff on April 21st, 2009 by sway – Be the first to commentThe largest upgrade issue we experienced in upgrading from MySQL 4 to MySQL 5 was in the select statement from multiple tables.
To help you on your way (if you have not-well formatted queries) we provide this example:
MySQL 4 query: SELECT * FROM X, Y, Z WHERE A and B and C
MySQL 5 query: SELECT * FROM (X, Y, Z) WHERE A and B and C
The reason: Apparently, in MySQL 5, there is some confusion as to where the fields come from, even if they are uniquely named and labeled with the table name preceding the field name. Without the parens to collect the tables from which the data is selected, it is the default action of MySQL 5’s interpreter to consider only either the first or last table in the list of tables. This means that the query executed without parens will leave some of the fields in the where conditions without proper assignment/definition, and the query will fail.
Update Twitter using PHP
Posted in PhP Stuff on March 5th, 2009 by sway – 2 CommentsSo, we have recently started posting our blog headers to Twitter so that people can follow the threads more easily. To do so, instead of constantly updating our content in two places, we modified our wordpress blog to post directly to Twitter when we publish new articles to the tech blog.
I would say that it took about 6 minutes to integrate the code and test the new addition. You should be able to do the same in no time!
This code helps you to do 1) build a tinyURL so that any links you require are short; and 2) post content to your Twitter status updates using the Twitter API.
function add_to_twitter($link, $status){
$tinyURL = $this->get_tiny_url($link);
// Set username and password
$username = 'username';
$password = 'password';
// The message you want to send
$status = $status . " " . $tinyURL;
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$status");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// check for success or failure
if(empty($buffer)){
echo "bad post";
}else{
echo "success";
}
}
//gets the data from a URL
function get_tiny_url($url){
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Sharing PHP Code among domains on a shared hosting account with GoDaddy
Posted in PhP Stuff, Tech Tips on February 18th, 2009 by sway – Be the first to commentContrary to what the GoDaddy Technical Support team tells everyone… you CAN (yes, you can) share code between multiple domains on a shared hosting account with GoDaddy!!!
Basically, I am sharing with you my work around for fact that we’re not allowed to create symlinks in the sub folders (which hold the content of the other domains (secondary, non-primary domains)) of our unlimited shared hosting account.
You can complete this work around in 3 easy steps!
- In the root directory of your unlimited hosting account, create a php5.ini file which is a copy of the already given php.ini file
- Add this line to your php5.ini file:
include_path = ".:/usr/local/php5/lib/php:/home/content/s/a/m/sample/html/shared_code" - Place some code in your shared_code directory and you are done!
You will be able to access the classes and any scripts you have in that directory by including the file with no path. This means your includes will look like this:
include ("SharedClass.php");
(You can also change your fopen status in your php.ini file, but you can use cURL to work around any other fopen issues holding you up)
NOTE: This solution assumes that you are running a Linux server (not Windows) and are using PHP 5 (although this solution may work for PHP 4 on Linux if you make the changes to the php.ini file and not the php5.ini file)
PhPDocs - Documentation App for PHP Code
Posted in PhP Stuff on February 18th, 2009 by sway – Be the first to commentWe have started to use PHPDocumentor to create JavaDocs-eqsue documentation of our PHP code.
The application itself is very easy to modify in the event that you want to alter the stylesheets to make the documents be more cohesive with your site, or if you are colorblind and want to get away from the tragic red-on-blue color scheme that is the current default.
Some tips:
When documenting parameters using the @param tag format your documents as follows:
@param type $name description to follow
@param type $name2 description to follow
When documenting return type, you can either leave the return type blank (exclude the tag) and you will have a return type of void, or you can document your non-void return type as follows:
@return string description to follow
in my examples, “description to follow” is where I go into detail about the significance of the parameter or return object.
Also, be sure to format your comments like so:
/**
* @param type $name
* @param type $name2
* @return type
*/
How to get a Wordpress API Key for use with Plugins like Akismet
Posted in Tech Tips on February 18th, 2009 by sway – 2 CommentsYour Wordpress API key is a 12 digit (SECRET) code located in your user profile that allows you enable various blog related plugins through your wordpress blog.
In order to get a WordPress API key you first need an account at WordPress.com. If you have, or had a free WordPress blog hosted on WordPress.com, chances are you already have an API key.
First go to WordPress.com. and click ‘Sign Up’ in the top right side of the site as shown below. Please note that the login information for WordPress.com is completly different than that to login to your self-hosted WordPress blog!!!
After you sign up at WordPress.com you will receive an email with a link you need in order to activate your new account. Once that is done, you have two methods of retrieving your API Key. You can either:
1) wait for the account creation confirmation email which contains your account username and password as well as the text “Your WordPress.com API key allows you to use services like Akismet @ http://akismet.com/ API Key:” followed by a 12 digit alphaneumeric sequence which is your API Key
- or -
2) login to your newly created Wordpress.com account and find your API Key which is located at the top of your user profile screen following the text: “Your WordPress.com API key is: ”
(Access your user profile by clicking MyAccount > Global Dashboard and then clicking on either your username in the top right which will launch your user profile screen, or by selecting your user profile from the Users list in the menu.)