eire web design home page contact eire-web design eire web design and development site map
stepping on in business
• Welcome to Eire Web Design Ireland

Archive for April, 2008

Debugging Live Website

Thursday, April 3rd, 2008

Debugging a live website it’s a pain in the neck, especially if you are working on changing database queries.
You can’t “echo” the SQL query to find out how is formatted and why the result are not the right ones, but you CAN “Email” it to yourself and check it out when it arrives in your inbox.

This is exactly what the php function below will do:
( just change the myemail@server.com to your email address )

function ewd_email_sql($sSql){  $my_email = "myemail@server.com";//set your email address

  $my_subject = "SQL Query Email";//email subject

  $my_message = !empty($sSql) ? $sSql : "SQL Query was empty";

  $my_ip = ""; //enter your IP ADDRESS to make sure you only send the email when you view this page

$mime_boundary = "<<<--==+X[".md5(time())."]\r\n\r\n";// Generate a boundary string

  $headers = "From:".$my_email."\r\n".

                "To:".$my_email."\r\n".

                 "MIME-Version: 1.0\r\n" .

                 "Content-Type: text/plain;\r\n".

                 "boundary=\"".$mime_boundary."\"\r\n";

  if(!empty($my_ip) && $_SERVER['REMOTE_ADDRESS'] == $my_ip){

    mail($my_email,$my_subject,$my_message,$headers);

  }

  return;

}

//usage e.g

$sSql = "SELECT * FROM table_name WHERE something='".addslashes("something_else")."'";

  //email it

  ewd_email_sql($sSql);//call function

..............

//rest of the code below

Hope it helps…

Links...

Chicklets...
  • http://www.eire-webdesign.ie/blog/feed/
    http://www.eire-webdesign.ie/blog/feed/
    Google Reader or Homepage
    Add to My Yahoo!
    Subscribe with Bloglines
    Subscribe in NewsGator Online
    add to msn
    Add to My AOL
    Add to Technorati Favorites!
    pageflakes
    windows live