Friday, December 30, 2011

Attach database failed : "Unable to open the physical file "....". Operation system error 5: "5(Access is Denied)". Microsoft SQL Server, Error: 5120)

If you receive this follow error while you are trying to attach you old or back-up database mdf file to your Microsoft SQL Server 2008, you can fix it by using the methods mentioned below.

Attach database failed .................
"Unable to open the physical file "....". Operation system error 5: "5(Access is Denied)". Microsoft SQL Server, Error: 5120)

There are several ways of fixing it. I looked for the solutions and found these 3 methods from http://blog.sqlauthority.com. Here, I am going to re-share them again.


Method 1. ----- Tested
CREATE DATABASE ygnonline ON
(FILENAME = N'D:\MyProjects\myapps\database\mydb_Data.mdf')
FOR ATTACH_REBUILD_LOG
GO
***The log file (.ldf) will be recreated.

Method 2.

EXEC sp_attach_single_file_db @dbname='TestDb',
@physname=N'D:\MyProjects\myapps\database\mydb_Data.mdf'
GO


Method 3.

CREATE DATABASE ygnonline ON
(FILENAME = N'D:\MyProjects\myapps\database\mydb_Data.mdf')
FOR ATTACH
GO


I never try myself on method 2 and 3 since the issue I have is fixed with the method 1. Please kindly be advised to check with your database expert before using above methods in live or production environment.
You can also go and read TechNet library of Microsoft for more details in this.
Wish you guys can fix all the bugs you got before coming of the new year!!! Good Luck!! Enjoy!!! All the best!!!!!!

Wednesday, December 28, 2011

PHP Fatal error : Cannot break/continue 1 level

Because you are using break without "switch...case" or looping. You can solve this by changing "break" to "return" to exit from the function.

Enjoy!!! .. all the best... :)

Monday, December 26, 2011

Where does MySQL database stored its data in my harddisk?

Where does MySQL database stored its data in my harddisk?

It depends on where you want it to be stored. Normally you can find the location of your mysql data files in this following config file.

C:\Program Files\MySQL\MySQL Server 5.1\my.ini

If you are using XAMPP, you can find it in here :

D:\xampp\mysql\bin\my.ini

But you may not need to look into that file since you can find your data files in this follow directory.

D:\xampp\mysql\data


Enjoy!! Thanks...
"Correct my if i am wrong by leaving comments down there" :D

Sunday, December 25, 2011

Keyboard shortcuts for Windows


Most of you guys may already have known this combination of this shortcut key on Windows Platform.
I would like to share with you guys about some of the common keyboard shortcuts for windows
Windows Key(windows logo) + M : Minimize all windows 
Windows Key(windows logo) + Shift +M : Undo minimize all windows
Windows Key(windows logo) + F : Open search dialog box to search or find files or folders in your entire computer or your specified area of your computer.
Windows Key(windows logo) + Break : Open system properties window
Windows Key(windows logo) + L : Lock your computer or log off from your windows
Windows Key(windows logo) + Tab : Cycling windows

Ctrl + ESC: Opens the Start menu (use the ARROW keys to select an item)
Ctrl + Tab : Switch between tabs or child windows which are opening in the same windows
Ctrl + T : Redo last done action (it is only available for some applications)



Friday, December 23, 2011

MySQL : "The user specified as a definer ('root'@'%') does not exist"

If you've found following error while using mysql database:
The user specified as a definer ('root'@'%') does not exist
Then you can solve it by using following :
grant all on *.* to 'root'@'%' identified by 'password' with grant option;

Wednesday, December 21, 2011

Using Flexigrid with PHP and MySQL

Flexigrid is a lightweight but rich data grid with resizable columns and a scrolling data to match the headers, plus an ability to connect to an xml based data source using Ajax to load the content.
Features :

  • Resizable columns
  • Resizable height and width
  • Sortable column headers
  • Cool theme
  • Can convert an ordinary table
  • Ability to connect to an ajax data source (XML and JSON[new])
  • Paging
  • Show/hide columns
  • Toolbar (new)
  • Search (new)
  • Accessible API

There are two formats you can get your data return to your page, in JSON or XML.

Follow this link, you can find a sample source code for returning in XML format, and for returning in JSON, follow here.

How it  works:
First, you have to these three lines to your html page

<link rel="stylesheet" type="text/css" href="flexigrid/css/flexigrid.css"> 
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="flexigrid/js/flexigrid.js"></script> 

Please make sure that you add  <script type="text/javascript" src="jquery.js"></script>  before <script type="text/javascript" src="flexigrid/js/flexigrid.js"></script> since it is using jquery to populate its grid.

then you can add the table definition which you want to show in your web page.
In this following example, the data will display in "flex1" table. 
And the data will be processing in post2.php file and return to your html page in JSON format.

<table id="flex1" style="display:none"></table> 
<script type="text/javascript"> 
$("#flex1").flexigrid({ 
        url: 'post2.php', 
        dataType: 'json', 
        colModel : [ 
                {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'}, 
                {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, 
                {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, 
                {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, 
                {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'} 
                ], 
        searchitems : [ 
                {display: 'ISO', name : 'iso'}, 
                {display: 'Name', name : 'name', isdefault: true} 
                ], 
        sortname: "iso", 
        sortorder: "asc", 
        usepager: true, 
        title: 'Countries', 
        useRp: true, 
        rp: 15, 
        showTableToggleBtn: true, 
        width: 700, 
        onSubmit: addFormData, 
        height: 200 
}); 

To get to the point here, please follow below steps to use Flexigrid in your webpage (in php or any languages) with MySQL or any databases.
Let's assume that you already had jquery.js in your root directory.
Step 1:
<link rel="stylesheet" type="text/css" href="flexigrid/css/flexigrid.css"> 
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="flexigrid/js/flexigrid.js"></script> 

Step 2:
<table id="flex1" style="display:none"></table> 
<script type="text/javascript"> 
$("#flex1").flexigrid({ 
        url: 'post2.php', 
        dataType: 'json', 
        colModel : [ 
                {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'}, 
                {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, 
                {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, 
                {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, 
                {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'} 
                ], 
        searchitems : [ 
                {display: 'ISO', name : 'iso'}, 
                {display: 'Name', name : 'name', isdefault: true} 
                ], 
        sortname: "iso", 
        sortorder: "asc", 
        usepager: true, 
        title: 'Countries', 
        useRp: true, 
        rp: 15, 
        showTableToggleBtn: true, 
        width: 700, 
        onSubmit: addFormData, 
        height: 200 
}); 

**if you want to use xml, just replace
dataType: 'json' with datatype:'xml'.

Steps 3: Create the processing page in php or any language you like.
Here is the sample pages in php format. please find json and xml

You can use $("#flex1").flexReload(); to reload or refresh your flexigrid. But you have to put it in right location in order to use it effectively.

And you can find full sample source codes for flexigrid at https://code.google.com/p/flexigrid/source/browse/#svn%2Ftrunk%2Fdemo

Download flexigrid directly here. or go to flexigrid.info for more detail.

Be remind yourself not to forget ; semi-colon and cases since both javascript and php are case-sensitive scripting engines.

All the best!!! Enjoy!!!



Sunday, December 18, 2011

Binding data to dropdown list with php from mysql database

This is just a basic for some of you guys. But if you are new to it, it will take some times for you to figure it out. So, please follow the steps mentioned below, and you will get there in no time.

<select name="yourselection">
    <option value="">--Select--</option>
    <?php
$msql = mysql_query("SELECT * FROM manufacturer");
while($m_row = mysql_fetch_array($msql))        
        echo("<option value = '" . $m_row['m_code'] . "'>" . $m_row['m_name'] . "</option>");
  ?>
</select>