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'); }

2007/03/12

How to schedule the deletes task

  1. Open C drive. Create a new folder named “tool” and copy “mydel.bat” into “C:\tool”
  2. Open “mydel.bat” using NOTEPAD. Change C:\ “documents and settings”\Cindy\“my document”\test to the path of back up folder. E.g C:\masslynx\systembackup new line: C:\masslynx\systembackup\*.* save the file.

    echo y del C:\"Documents and Settings"\Cindy\"My Documents"\test\*.*

  3. Run schedule task
    Start
    All programs
    Accessories
    System tools
    Schedule task
  4. Click “add scheduled task”
    next
    Brower to find the file at “C:\tool\mydel.bat”
    schedule time (two steps)
    User name is on the screen or = full computer name\user name
  5. Right click “my computer”
    Properties
    Find computer name
    User name is the log in name
    Password is the log in password
    Click finished without check the option of “open advanced….”

2007/03/08

my $line_old = $_; my $line = $line_old; my @lines = split (/,/ , $line); foreach my $item (@lines) { do something } $line = join ("," , @lines); ####split does not take the trailing empty element if ($old_line =~ /.*(,+)$/) { $line .= $1; }

2007/01/16

GD graphics library in PHP

GD 2.0 or later (built in to PHP since version 4.3 or so, but you might need to recompile PHP or contact your host if it's not working).

GD is the graphics library that ZenPhoto is based on. Normally, it should come already compiled in with your PHP executable, but as I found out, it's not always the fact.

Here's how to enable GD2 in PHP:
1) If you have access to your php.ini file...
• Open it up in your favorite text editor and look for the following line (near the middle):
;extension=php_gd2.dll
change it to
extension=php_gd2.dll
(basically, remove the semi-colon in front)
• Save the file and upload it back on the server and overwrite the old file.
• Restart your server
• That's it!