06 December 2010

Fix MySQL Character Encoding Problem UTF-8 PHP

While gathering data from Mysql database i got character encoding problems when my tables have non-english text.
I found a solution that completly solves character encoding problem while you calling your sql queries.

Simply set your character set before you call a sql query.
$myconnection= mysql_connect(DB_SERVER, DB_USER, DB_PASS)
or die(mysql_error());
mysql_select_db(DB_NAME, $myconnection) or die(mysql_error());
mysql_set_charset('utf8',$myconnection);

mysql_set_charset method sets your character set before the calls.
Don't forget to encode your php files to utf-8, or what encoding you want to encode with.

25 May 2009

ASP.NET How To access Master Page Variables Class Members C#.NET

Sometimes we need to access to a variable in master page file.
For example I need to change the body onload event in html.

In the asp.net file, we simply cast our master page as its class name.

in master page aspx we add the code below.

<body onload="<%=myloadstr %>" >

in master page cs code we add the code below.
we declare it as public to access the variable.

public string myloadstr = "";


And add the code below in your asp.net cs source file.

((myMasterPage)this.Master).myloadstr = "here some javascript for load";

myMasterPage is the name of my masterpage class. We cast our asp.net page its masterpage, with "this.Master".

22 May 2009

Run PHP On Local Machine

When I want to develop a php website, it is always be hard to run and test the php code on local machine.
After I search how to run php on local machine, I found an awesome tool for this.


XAMPP is a great open source software that helps you run php on local, and also it runs MySQL Server service, Filezilla FTP.

Simply download xampp and install it, I select the run apache as service option.

By its default, it installs into C:\xampp directory,
you can copy your php files into C:\xampp\htdocs directory, and open in your browser.

16 December 2008

C# MS Access Connection String OLE DB OleDbConnection

The Connection String for MS Access can be set as ;
 private constr =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=yourdbfile.mdb;
Jet OLEDB:Database Password=yourpassword;";
And the C# code to connect to MS Access database ;
 public bool OpenConnection()
{
OleDbConnection con; con = new OleDbConnection(constr);

if (con.State != ConnectionState.Open)
{
try
{
con.Open(); return true;
}
catch (Exception) { return false; }
}
else return false;
}
C# Access Connection String OLE DB OleDbConnection password field is the password you set up in access database.

Mobile Phone Hide Your Number

To hide your number when you are calling someone with your mobile phone,
simply add *31# in the beginning of the number you will call.

hide number
*31#

Imei Number Learn Your Mobile Phone Imei Number

You can easily learn you mobile phone's IMEI number
by pressing star square 06 square

*#06#

11 December 2008

C# Read Harddisk Serial Number WMI ManagementClass Win32_LogicalDisk

With the Win32_LogicalDisk Management path we can reach the local disk information.

Even you can read harddisk serial number,
size, partitions, free space and so on.

Now let's read the serial number of a harddisk in C# with ManagementClass WMI.
public static string HardDiskID()
{
ManagementClass partionsClass = new ManagementClass("Win32_LogicalDisk");
ManagementObjectCollection partions = partionsClass.GetInstances();

string hdd = string.Empty;

foreach (ManagementObject partion in partions)
{
hdd = Convert.ToString(partion["VolumeSerialNumber"]);

if (hdd != string.Empty)
return hdd;
}

return hdd;
}
This static function will simple give us the volume serial numbers.
C# Read Harddisk Serial Number WMI ManagementClass.