RSS
magnify
formats

How to backup all mysql databases

Published on April 26, 2012 by in Linux, mysql

In order to backup all mysql databases, you can run the following command in your linux command line:

The example below is configured with username “theuser” and password “thepass”.

mysqldump -utheuser -pthepass –all-databases > all_dbs.sql
 
Tags: ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Invalid command ‘RewriteEngine’

Published on April 26, 2012 by in .htaccess, Apache

If you receive the following error message if means that mod_rewrite is not enabled in Apache:

Invalid command ‘RewriteEngine’, perhaps misspelled or defined by a module not included in the server configuration.

a2enmod rewrite

Bear in mind this is done like this on Linux Ubuntu, not entirely sure if this works for other flavours too.

 
Tags: ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Warning: Invalid argument supplied for foreach()

Published on February 28, 2012 by in error, php

A common error which occurs with foreach loops is the standard “Invalid argument supplied for foreach()” whch gets thrown up as a warning.

This can easily be overcome by wrapping the foreach loop in a conditional if statement which checks to see if the argument supplied to the loop is an array or not.

Below is an example of how to correct the problem:

if (in_array($arrItem)) {
foreach($arrItem as $arrItemi) {
// use $arrItemi;
}
}
 
Tags: , ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
1 Comment  comments 
formats

Unable to connect to any of the specified MySQL hosts.

Published on February 19, 2012 by in Linux, mysql

If you get the following error while trying to connect to a MySQL database using a third party client such as TOAD or SQL Workbench, then you need to edit your mysql server’s my.cnf file.

Error Message: Unable to connect to any of the specified MySQL hosts.

So open the my.cnf file by running a similar command to the following one dependent on your server’s setup:

vi /etc/mysql/my.cnf

Then edit the bind-address from what is probably set as 127.0.0.1 (also known as localhost) to your server’s remotely accessible IP address.

If you are unsure what your server’s IP address is then you need to ping it from the command line on another machine outside it’s network (e.g. your own machine) as follows:

ping yourhost.com

N.B. If you are running a Dovecot/Postfix type email gateway setup on the same machine, changing your mysql bind-address will affect it’s connection to the database and you will no longer be able to send/receive emails through it. So you will have to adjust your Dovecot/Postfix configuration files where relevant.

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

PHP nl2br on one line

Published on February 18, 2012 by in php

I usually store data from a textarea directly to the database as is, then once I retrieve it back into HTML I use that lovely PHP function nl2br() to convert it to HTML
tags.

This works well for most cases until you are passing this data back into javascript where everything has to be on one line!

nl2br() outputs as follows:

Line one

Line two

And I want it to be as follows:

Line one
Line two

So how do I do this?

echo trim(strtr($myOriginalString, array("\r\n" => "<br />", "\r" => "<br />", "\n" => "<br />")));
 
Tags: ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

fb:login-button not showing on IE8

Make sure you have the following code at the start of your HTML header document

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
 
Tags: ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

LEN in MySQL

Published on February 1, 2012 by in MSSQL, mysql

In MySQL 5.1 LEN is called LENGTH, you use it exactly the same and pass in the link, so: LENGTH(link).

 
Tags: , , ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
1 Comment  comments 
formats

Remove all linebreaks in PHP

Published on January 30, 2012 by in php

If you are having problems with a string that keeps adding a line break when output from PHP to HTML then the following code will work wonders for you!

$string_with_line_break = "blabla\nbla\r";
$string_without_line_break = trim(preg_replace( "/\s+/","",$string_with_line_break));
 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

IE9 adding empty table cells in large table

Well as usual, we are once again fighting the woes of the beloved Internet Explorer, and it appears that Microsoft’s latest greatest new and improved browser rival to the market IE9 still has a whole bunch of irritations and retardation to worry about (saw that one coming).

Today I was busy loading a massive amount of data into the body of a table using ajax and in Firefox and even Internet Explorer 8 it worked quite well, but Internet Explorer 9 decided that it would like to add some empty table cells randomly around my “massive table”, now of course I began by kicking something and cried a few times….. but then I thought about whitespacing and the usual problems I had found with it before while using “the best browser ever known to human-kind”(…not) and I thought of removing the whitespaces between the <tr>’s and <td>’s.

Sample code while crying and trying to get rid of the ironious cells:

<table>
<tbody>
<tr>
<td>Some text here 1</td>
<td>Some text here 2</td>
<td>Some text here 3</td>
<td>Some text here 4</td>
</tr>
</tbody>
</table>

The really dumb thing that fixed IE9’s problems:

<table>
<tbody>
<tr><td>Some text here 1</td><td>Some text here 2</td><td>Some text here 3</td><td>Some text here 4</td></tr>
</tbody>
</table>

 

 

And voila! Remove the whitespaces yourself and IE9 won’t get confused!

 
Tags: ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
9 Comments  comments 
formats

SELECT Duplicate Items Using SQL

Published on December 20, 2011 by in MSSQL, mysql, sql

If you have a table which has duplicate items in then you can use the below statement to select them.

SELECT * FROM tableName
GROUP BY columnName
HAVING ( COUNT( columnName) >1 )
 
Tags:
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

MySQL Error: Can’t get hostname for your address

Published on December 14, 2011 by in error, mysql

This error is thrown by MySQL because it tries to do a DNS lookup on the address connecting to the server and it fails due to the IP not being able to be resolved back to a name or some-other deeper DNS bust problem.

The easiest way to fix this is to edit your my.ini or my.cnf (/etc/my.cnf) and in the
[mysqld] section add the “skip-name-resolve” option.

Near the top of the file this will look similar to the below:

[mysqld] skip-name-resolve
 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Adobe drops flash for mobiles!

Published on November 9, 2011 by in adobe

..and it’s official – so says Adobe’s blog (read it here). Adobe will be dropping support for Flash on future devices due to performance and a few other things, pushing the future more towards the HTML5 route, which isn’t neccessarily a bad thing, I just find it quite ironic and somewhat comical that they waited for Steve Jobs (Apple) to die before giving up their long time fight with Apple about Flash being or not being supported on mobile devices, namely the iPhone.

Read more here: http://blogs.adobe.com/flashplatform/2011/11/flash-to-focus-on-pc-browsing-and-mobile-apps-adobe-to-more-aggressively-contribute-to-html5.html

 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
© Copyright © 2012 · Web Development London UK · All rights reserved · Site hosted on the hsmoore.com network
By using the site and/or making use of any of our services you agree to our Terms and Conditions