2009/02/26

Solutions of database replication failure

MySQL replication allows you to have an exact copy of a database from a master server on another server (slave), and all updates to the database on the master server are immediately replicated to the database on the slave server so that both databases are in sync. (instrested in how this being set up, check it out here, http://www.howtoforge.com/mysql_database_replication)
My compare have two web servers, and the replication is turning on. We use below php file to check the replication status.  
$link = mysql_connect('localhost', 'root', 'password')
   or die('Could not connect: ' . mysql_error());
mysql_select_db('production') or
    mail('example@email.com', 'www cannot connect', $message);
$query = 'SHOW SLAVE STATUS';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);
if ( $line["Slave_SQL_Running"]  != "Yes"  or
     $line["Slave_IO_Running"]  != "Yes" ) {
    $message = $line["Last_Error"];
    mail('example@email.com', 'www replication failure', $message);
}
?>
During the development, we created a database on slave DB, and today we were going to move the code to production, so we created a database on master DB. It used the samed name as the same one on slave DB, but having nothing in there. A few minutes later, we got email telling us the repliation failed.
Here is a solution:
On Slave:
1. In phpMyAdmin export the Database (For example, named A)
2. Drop the Database (A)
3. logon mysql, run command: START SLAVE (It would try to rerun the queries)
On Master:
1. Drop the Database (A);
2. Create a Database using different name (B)
On Slave:
Import the Database using the Export file.

2009/02/24

Fixed postion in IE6

To have something always shown on the same position on a page, we can use css position property and set it to "fixed", however it doesnot work in IE6. There might be some hack to make this happen in IE6, actually I searched along trying to find one, but have not find a good solution yet. Anyway I am not going to spend time on the IE hack, what I going to do is just hidded this funtion in IE6. Complaint? Who care! Why not just leave that old buggy stupid IE6, you have a lot of option, have not you?
So the html code is like this:
<div id="footerud">
<div id="up"></div>
<div id="down"></div>
</div>
The css is that:
#footerud{bottom:10px;display:block !important;position:fixed;left:15px;}
#up{
background:url(../images/arrowtop.png) no-repeat;
cursor:pointer;
height:14px;
margin-bottom:15px;
position:relative;
width:25px;
}
#down{
background:url(../images/arrowbottom.png) no-repeat;
cursor:pointer;
height:60px;
margin-top:15px;
position:relative;
width:25px;
}  
To hidded this on IE6, I added style into html code, like
<div id="footerud" style="display:none;">
 
Will that hidded it from Firefox or IE7? Don't worry, because we have this in the css file,
#footerud{bottom:10px;display:block !important;position:fixed;left:15px;}
The !important generally means the attribute cannot be overwrote, fortunately, IE6 does not recognized it, so it will be hid.
 

2009/02/23

'nodeName' is null or not an object error in IE

Says you have code like below
<div id="place1">ABC</div> ... <div id="place2">EFG</div> Then you try to update those div using jquery's html method, and the html result from ajax will be insert into this div, like
$('#change').html(data); //data is from ajax call Which works fine on Firefox, but fails on IE. The message you will get is that, 'nodeName' is null or not an object The fixes is that clearing the value in that div before assign anything into it, like,
$('#change').html(); //clear div $('#change').html(data); The version of the jQuery used to product this error is 1.2.6

jquery ajax with xml

1. How to generate XML output By default, echo in php sending the text to the browser. So it you try to generate xml output, you have to send the header before xml output to tell teh browser it is xml, like below: header("Content-Type: text/xml; charset=UTF-8"); $smarty->display('cart/popin.tpl'); 2. How to add html code in a xml node To have html in a xml node, you have to use CDATA:

A CDATA section starts with "<![CDATA[" and ends with "]]>":

3. how to use jquery to get XML respond $.ajax({ url: $(this).attr('href'), type: 'GET', dataType: 'xml', timeout: 1000, error: function(){ alert('Error loading XML document'); }, success: function(xml){ // do something with xml //alert('what\'s next'); $('#buynow-result').html($(xml).find('pop').text()); $('#buynow-inform').show('slow'); }