<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"><channel><title>Code Snippets</title><description>Simply, It's a blog to share code snippets.</description><managingEditor>noreply@blogger.com (Tarek N. Elsamni)</managingEditor><pubDate>Fri, 1 Nov 2024 12:35:01 +0200</pubDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">10</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">25</openSearch:itemsPerPage><link>http://codesnippetsstore.blogspot.com/</link><language>en-us</language><itunes:explicit>no</itunes:explicit><itunes:image href="http://www.beyond-dev.com/images/logo.png"/><itunes:keywords>C,Java,Javascript,LINQ,WPF,WCF,C,PHP,Programming,Code,Visual,Studio,Library,Controls,Windows,Forms,Query,SQL,MYSQL,MSSQL,sql,server</itunes:keywords><itunes:summary>This blog is to share my code snippets in C#(ASP.NET, WCF, WPF, LINQ and windows applications), PHP, C++, Java, Javascript, CSS and XHTML.</itunes:summary><itunes:subtitle>The best code snippets ever</itunes:subtitle><itunes:category text="Education"><itunes:category text="Educational Technology"/></itunes:category><itunes:owner><itunes:email>noreply@blogger.com</itunes:email></itunes:owner><item><title>Generating a Property Stub  | Get Ready For C# 4.0</title><link>http://codesnippetsstore.blogspot.com/2010/04/generating-property-stub-get-ready-for.html</link><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Sun, 25 Apr 2010 02:46:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-701479736394590726</guid><description>If code references an undefined property, click Generate property stub. The property stub is generated in the appropriate class. The property’s return type is determined from the context.&lt;br /&gt;
&lt;br /&gt;
For example, assume that you generate the InstanceProperty property from the statement in the following code.&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
Customer cust = new Customer();
string city = cust.InstanceProperty;
]]&gt;&lt;/script&gt;&lt;br /&gt;
When you generate the property, the following stub is created in the Customer class.&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
When you generate the property, the following stub is created in the Customer class.
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
If a property is invoked on a type and not an instance, the generated stub will be a static property (C#) or a shared property (Visual Basic).&lt;br /&gt;
&lt;br /&gt;
For example, imagine that you generate a property from the following statement (assuming that Customer is a class name).&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
string description = Customer.StaticProperty;
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
When you generate the property, the following stub is created in the Customer class.&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
public static string StaticProperty { get; set; }
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
If a property is invoked without a qualification (referring to a member of the current type), the generated stub is static if the property is called from a static method. Otherwise, it is an instance property.&lt;br /&gt;
&lt;br /&gt;
For example, assume that you generate a property from the following statement.&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
string title = UnqualifiedProperty;
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
When you generate the property, the following stub is created in the current class.&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
public string UnqualifiedProperty { get; set; }
]]&gt;&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Indexed properties | Get Ready For C# 4.0</title><link>http://codesnippetsstore.blogspot.com/2010/04/indexed-properties-get-ready-for-c-40.html</link><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Sat, 24 Apr 2010 12:35:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-7589035368090562819</guid><description>Many COM APIs expose “indexed properties” which are essentially properties with parameters. C# will not allow you to declare indexed properties, but to the extent that non-C# APIs expose them, will now allow you to access these using element access syntax. So instead of&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
o.set_P(i+1, o.get_P(i) * 2);
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
You can now write the more intuitive&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
o.P[i+1] = o.P[i] * 2;
]]&gt;&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Dynamic import | Get Ready For C# 4.0</title><link>http://codesnippetsstore.blogspot.com/2010/04/dynamic-import-get-ready-for-c-40.html</link><category>.net</category><category>2010</category><category>4.0</category><category>C#</category><category>dynamic</category><category>import</category><category>studio</category><category>visual</category><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Sat, 24 Apr 2010 12:33:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-5872013909143748839</guid><description>Many COM methods accept and return “variant” types, which are represented in the PIAs as object. In the vast majority of cases, a programmer calling these methods already knows the static type of a returned object from context, but explicitly has to perform a cast on the returned value to make use of that knowledge. These casts are so common that they constitute a major nuisance.&lt;br /&gt;
In order to facilitate a smoother experience, if you choose to import these COM APIs with PIA-embedding, variants are instead represented using the type dynamic. In other words, from your point of view, COM signatures now have occurrences of dynamic instead of object in them.&lt;br /&gt;
This means that you can easily access members directly off a returned object, or you can assign it to a strongly typed local variable without having to cast. To illustrate, you can now say&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
excel.Cells[1, 1].Value = "Hello";

]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
instead of &lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
((Excel.Range)excel.Cells[1, 1]).Value2 = "Hello";
]]&gt;&lt;/script&gt;&lt;br /&gt;
and&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
Excel.Range range = excel.Cells[1, 1];
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
instead of&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
Excel.Range range = (Excel.Range)excel.Cells[1, 1];
]]&gt;&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Optional (or Default) Parameters | Get Ready For C# 4.0</title><link>http://codesnippetsstore.blogspot.com/2010/04/optional-or-default-parameters-get.html</link><category>.net</category><category>2010</category><category>4.0</category><category>C#</category><category>Default Parameter</category><category>studio</category><category>visual</category><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Sat, 24 Apr 2010 01:19:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-592101842452978823</guid><description>I see that people have been asking for this feature since C# 1.0. Three versions later, it’s finally here.&lt;br /&gt;
&lt;br /&gt;
Now you can assign a default value to a parameter right within the method declaration. The user of the method can either pass a value or simply skip the argument. In the latter case, the default value is passed to the method.&lt;br /&gt;
&lt;br /&gt;
Method declaration:&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
public static void SomeMethod(int optional = 0) { }
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Method calls:&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
SomeMethod(); // 0 is used in the method.
SomeMethod(10);
]]&gt;&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Dynamic Keyword | Get Ready For C# 4.0</title><link>http://codesnippetsstore.blogspot.com/2010/04/dynamic-keyword-get-ready-for-c-40.html</link><category>.net</category><category>2010</category><category>4.0</category><category>C#</category><category>dynamic</category><category>studio</category><category>visual</category><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Sat, 24 Apr 2010 01:14:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-6585693192937769249</guid><description>The dynamic keyword is a key feature of this release. It closes the gap between dynamic and statically-typed languages. Now you can create dynamic objects and let their types be determined at run time. With the addition of the System.Dynamic namespace, you can create expandable objects and advanced class wrappers, and you can provide interoperability between different languages, including dynamic ones. Here is one quick example:&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
dynamic contact = new ExpandoObject();
contact.Name = "Patrick Hines";
contact.Phone = "206-555-0144";
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
More Complicated Example:&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
public static void DynamicObjectExample()
{
    dynamic myVar = new ExpandoObject();

    // Add object properties in runtime.
    myVar.MyProperty1 = "MyProperty1";
    myVar.MyProperty2 = "MyProperty2";

    // Add method in runtime.
    myVar.MyMethod = (Action)(() =&gt; { Console.WriteLine("MyMethod"); });

    // Add Event in runtime.
    myVar.MyEvent = null;
    myVar.MyEvent += new EventHandler(MyEventMethod);

    // Print
    Console.WriteLine(myVar.MyProperty1);
    Console.WriteLine(myVar.MyProperty2);
    myVar.MyMethod();
    myVar.MyEvent(myVar, EventArgs.Empty);

    // Output: 
    // MyProperty1
    // MyProperty2
    // MyMethod
    // System.Dynamic.ExpandoObject
    // System.EventArgs

}


public static void MyEventMethod(object s, EventArgs e)
{
    Console.WriteLine(s.ToString());
    Console.WriteLine(e.ToString());
}
]]&gt;&lt;/script&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Simple WCF chat application with database (LINQ)</title><link>http://codesnippetsstore.blogspot.com/2010/01/simple-wcf-chat-application-with.html</link><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Thu, 14 Jan 2010 14:47:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-986199948398336711</guid><description>This project will be consisted of a WCF service (ISERVICE [Interface] &amp; SERVICE [C# code to implement the interface]), Server Application which will use the WCF service and finally the client(Windows Form).&lt;br /&gt;
&lt;br /&gt;
In our SERVICE we will have 2 Interfaces:&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
    public interface IChat
    {

        [OperationContract]
        int Register(string Username, string Password);

        [OperationContract]
        int Login(string Username, string Password);

        [OperationContract]
        void AddFriend(string Username, string Friend);

        [OperationContract]
        void Logout(string Username);

        [OperationContract]
        List&lt;user&gt; GetOnlineFriends(string username);

        [OperationContract]
        List&lt;user&gt; GetOfflineFriends(string username);

        [OperationContract]
        void SayMsg(ChatMessage MSG, string To);
       
    }
   

    [ServiceContract]
    public interface IChatCallback
    {

        [OperationContract]
        void NewUserLoggedon(string name);

        [OperationContract]
        void NewUserLoggedoff(string name);

        [OperationContract]
        void NewMSG(ChatMessage MSG);
    }
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
The first Interface will be Implemented in Service.cs as the WCF service to make Server side operations like:&lt;br /&gt;
Register, Login, logout and Add Friend.&lt;br /&gt;
&lt;br /&gt;
for Example:&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
    public int Register(string Username, string Password)
        {
            ChatDBDataContext DB = new ChatDBDataContext();

            var Users = from U in DB.users
                       where U.username == Username &amp;&amp; U.password == Password
                       select U;
            foreach (user user in Users)
            {
                return 0;
            }
            user NewUser = new user();
            NewUser.username = Username;
            NewUser.password = Password;
            DB.users.InsertOnSubmit(NewUser);
            DB.SubmitChanges();
            return 1;
        }
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ths second Interface will be Implemented in the client form as a callback mehods which will be used by server to make changes in form's data to represent changes in server side.&lt;br /&gt;
&lt;br /&gt;
for example:&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: c#"&gt;&lt;![CDATA[
    public void NewMSG(ChatSvc.ChatMessage MSG)
        {
            textBox6.AppendText(MSG.Content);
            label8.Text = "Last msg recieved: " + MSG.CurTime;
        }
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
This Application Full Source can be downloaded from this link:&lt;br /&gt;
&lt;a href="http://www.beyond-dev.com/examples/ChatApplication.zip"&gt;Download&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
To Test this application you need first to import application MSSQL named: ChatDB.mdf in the attached file and run the server project then run the client to test it.</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total></item><item><title>How to hide characters from being displayed on screen as they are keyed in?</title><link>http://codesnippetsstore.blogspot.com/2010/01/how-to-hide-characters-from-being.html</link><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Tue, 12 Jan 2010 11:00:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-2369096550130047719</guid><description>As has been mentioned, standard C keyboard input routines (getc, fgets, scanf, etc.) buffer the input until you press "Enter" --- and they echo each character as its key is pressed.&lt;br /&gt;
&lt;br /&gt;
Old-style DOS functions like getch() are still available in certain Windows command-line application compilers (such as Borland C, for example). getch() returns the character to the calling program but doesn't echo it to the screen.&lt;br /&gt;
&lt;br /&gt;
Here is a routine that I picked up somewhere some time ago (sorry, I didn't record the source, but I am quite sure I didn't delete any copyright notice). If it turns out that it is copyrighted or patented or something: let me know.&lt;br /&gt;
&lt;br /&gt;
I compiled and executed it on my Linux system, and also on my windows system (using CYGWIN gcc). Output looks the same.&lt;br /&gt;
&lt;br /&gt;
Here's the function, called linux_getch():&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: cpp"&gt;&lt;![CDATA[
    #include &lt;stdio.h&gt;
#include &lt;termios.h&gt; 
#include &lt;unistd.h&gt;

#define END_FILE_CHARACTER 0x04  /* ctrl-d is unix-style eof input key*/


int linux_getch(void) 
{
  struct termios oldstuff;
  struct termios newstuff;
  int    inch;
  
  tcgetattr(STDIN_FILENO, &amp;oldstuff);
  newstuff = oldstuff;                  /* save old attributes               */
  newstuff.c_lflag &amp;= ~(ICANON | ECHO); /* reset "canonical" and "echo" flags*/
  tcsetattr(STDIN_FILENO, TCSANOW, &amp;newstuff); /* set new attributes         */
  inch = getchar();
  tcsetattr(STDIN_FILENO, TCSANOW, &amp;oldstuff); /* restore old attributes     */

  if (inch == END_FILE_CHARACTER) {
    inch = EOF;
  }
  return inch;
}

]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Here's a test program for linux_getch():&lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: cpp"&gt;&lt;![CDATA[
    #include &lt;stdio.h&gt;
int linux_getch(void);

int main()
{
  int kb_char;

  printf("\n\n  This is a test of a function that (more-or-less)\n");
  printf("  emulates the classic DOS \"getch()\" function.\n\n");
  printf("  The keyboard input is not echoed; each character is\n");
  printf("  is returned to the calling program as a key is pressed.\n\n");
  printf("  For test purposes, this program echos the hex value returned\n");
  printf("  from the keyboard input routine.\n\n");
  printf("Press any key(s)");
  printf(" (the keyboard routine is set so that ctlr-d is EOF).\n\n");
  while ((kb_char = linux_getch()) != EOF) {
    printf("%02X ", kb_char);
  }
  printf("\n\n  Function linux_getch() says that you entered EOF\n\n");
  return 0;
}



]]&gt;&lt;/script&gt;&lt;br /&gt;
</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></item><item><title>Upload a file using c# as client to a PHP server</title><link>http://codesnippetsstore.blogspot.com/2010/01/upload-file-using-c-as-client-to-php.html</link><category>C#</category><category>client</category><category>files</category><category>images</category><category>php</category><category>server</category><category>upload</category><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Mon, 11 Jan 2010 23:46:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-4670826785125923347</guid><description>We'll call the PHP script "upload.php", this is what it should contain: &lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: js"&gt;&lt;![CDATA[
    &lt;?php

$uploaddir = 'upload/'; // Relative Upload Location of data file

if (is_uploaded_file($_FILES['file']['tmp_name'])) {

$uploadfile = $uploaddir . basename($_FILES['file']['name']);

echo "File ". $_FILES['file']['name'] ." uploaded successfully. ";

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {

echo "File is valid, and was successfully moved. ";

}

else

print_r($_FILES);

}

else {

echo "Upload Failed!!!";

print_r($_FILES);

}

?&gt;
]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
and this is the C# code: &lt;br /&gt;
&lt;br /&gt;
&lt;script type="syntaxhighlighter" class="brush: js"&gt;&lt;![CDATA[
    System.Net.WebClient Client = new System.Net.WebClient ();

Client.Headers.Add("Content-Type","binary/octet-stream");

byte[] result = Client.UploadFile ("http://your_server/upload.php","POST","C:\test.jpg");

string s = System.Text.Encoding .UTF8 .GetString (result,0,result.Length );

]]&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>PHP random password generator</title><link>http://codesnippetsstore.blogspot.com/2010/01/php-random-password-generator.html</link><category>function</category><category>generator</category><category>password</category><category>php</category><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Mon, 11 Jan 2010 23:31:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-4838304147506582363</guid><description>PHP password generator is a complete, working random password generation function for PHP. It allows the developer to customize the password: set its length and strength. Just include this function anywhere in your code and then use it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script class="brush: php" type="syntaxhighlighter"&gt;
&lt;![CDATA[
    &lt;?php
 
function generatePassword($length=9, $strength=0) {
	$vowels = 'aeuy';
	$consonants = 'bdghjmnpqrstvz';
	if ($strength &amp; 1) {
		$consonants .= 'BDGHJLMNPQRSTVWXZ';
	}
	if ($strength &amp; 2) {
		$vowels .= "AEUY";
	}
	if ($strength &amp; 4) {
		$consonants .= '23456789';
	}
	if ($strength &amp; 8) {
		$consonants .= '@#$%';
	}
 
	$password = '';
	$alt = time() % 2;
	for ($i = 0; $i &lt; $length; $i++) {
		if ($alt == 1) {
			$password .= $consonants[(rand() % strlen($consonants))];
			$alt = 0;
		} else {
			$password .= $vowels[(rand() % strlen($vowels))];
			$alt = 1;
		}
	}
	return $password;
}
 
?&gt;
]]&gt;
&lt;/script&gt;&lt;br /&gt;
2ADQZNUV2VG8</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></item><item><title>PHP Class to Generate/Restore backup from/to MYSQL database</title><link>http://codesnippetsstore.blogspot.com/2010/01/php-class-to-generate-backup-from-mysql.html</link><category>backup</category><category>database</category><category>gz</category><category>iam_backup</category><category>load</category><category>mysql</category><category>php</category><category>restore</category><category>save</category><category>sql</category><author>noreply@blogger.com (Tarek N. Elsamni)</author><pubDate>Mon, 11 Jan 2010 19:23:00 +0200</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-3600027836709326949.post-8088580551235490867</guid><description>This PHP class will help you to take a backup from your MYSQL database as it will generate .gz file to be downloaded or stored on a specific path.&lt;br /&gt;
&lt;br /&gt;
First you need to include the PHP class to use it:&lt;br /&gt;
&lt;br /&gt;
&lt;script class="brush: php" type="syntaxhighlighter"&gt;
&lt;![CDATA[
    require_once("iam_backup.php");
]]&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Then you have 3 different ways to take the backup:&lt;br /&gt;
&lt;br /&gt;
&lt;script class="brush: php" type="syntaxhighlighter"&gt;
&lt;![CDATA[
    $backup = new iam_backup("localhost", "mysql", "root", "",
true, false, false);
  $backup-&gt;perform_backup(); 
]]&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script class="brush: php" type="syntaxhighlighter"&gt;
&lt;![CDATA[
$conn = @mysql_pconnect("localhost","root","");
  if(!$result)     // If no connection, return 0
  {
    echo "An error has occured. Could not connect to the server";
  }
  if(!@mysql_select_db("mysql"))  // If db not set, return 0
  {
    echo "An error has occured. Could not select the MySQL Database";
  }

  $backup = new iam_backup($conn);

  $backup-&gt;perform_backup(); 
]]&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script class="brush: php" type="syntaxhighlighter"&gt;
&lt;![CDATA[
$backup = new iam_backup("localhost", "mysql", "root", "",
true, false, true, "./file.sql.gz");
$backup-&gt;perform_backup();
]]&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
To restore a MYSQL database backup include restore class:&lt;br /&gt;
&lt;script class="brush: php" type="syntaxhighlighter"&gt;
&lt;![CDATA[
require_once("iam_restore.php"); 
]]&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Then start restoring process:&lt;br /&gt;
&lt;script class="brush: php" type="syntaxhighlighter"&gt;
&lt;![CDATA[
$restore = new iam_restore('path/to/backup/file', "localhost",
"DBName", "username", "userpwd");
            $restore-&gt;perform_restore();   
]]&gt;
&lt;/script&gt;&lt;br /&gt;
This class &amp;amp; more examples can be downloaded from this link: &lt;a href="http://www.beyond-dev.com/examples/iam_backup-1.2.zip"&gt;Download&lt;/a&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></item></channel></rss>