Friday 17 May 2013

PHP MySQLI Tutorial

What is MySQLI :

The MySQLi Extension (MySQL Improved) is a relational database driver used in the PHP programming language to provide an interface with MySQL databases.
MySQLi is an improved version of the older PHP MySQL driver, offering various benefits.
The developers of the PHP programming language recommend using MySQLi when dealing with MySQL server versions 4.1.3 and newer (takes advantage of new functionality).

Why Mysqli :

The MySQLi extension provides various benefits with respect to its predecessor, the most prominent of which are:
  • An object-oriented interface
  • Support for prepared statements
  • Support for multiple statements
  • Support for transactions
  • Enhanced debugging support
  • Embedded server support

MySQLi Vs MySQL

MySQLi MySQL
PHP version introduced 5.0 Prior to 3.0
Included with PHP 5.x yes Yes
MySQL development status Active development Maintenance only
Recommended by MySQL for new projects Yes - preferred option No
API supports Charsets Yes No
API supports server-side Prepared Statements Yes No
API supports Stored Procedures Yes No
API supports Multiple Statements Yes No
Supports all MySQL 4.1+ functionality Yes No


Here is a simple code that implements mysqli

<?php


 //CONNECT TO THE DATABASE
 $DB_HOST = 'HOST';
 $DB_USER = 'USERNAME';
 $DB_PASS = 'PASSWORD';
 $DB_NAME = "mysqlitest";

 $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
 
 
 if (mysqli_connect_errno()) {
  printf("Connect failed: %s\n", mysqli_connect_error());
  exit();
 }

 //CREATE TABLE
 $q = "CREATE TABLE user (id int AUTO_INCREMENT PRIMARY KEY, 
     name varchar(30))";
 $mysqli->query($q);
 
 //INSERT FEW VALUES
 $q = "INSERT INTO user VALUES (NULL, 'abc')";
 $mysqli->query($q);
 $q = "INSERT INTO user VALUES (NULL, 'bcd')";
 $mysqli->query($q);
 $q = "INSERT INTO user VALUES (NULL, 'xyz')";
 $mysqli->query($q);
 
 
 //SELECT A USER
 $q = "SELECT * FROM user WHERE id=3";
 $result = $mysqli->query($q) or die($mysqli->error.__LINE__);

 // GOING THROUGH THE DATA
 if($result->num_rows > 0) {
  while($row = $result->fetch_assoc()) {
   echo $row['name']; 
  }
 }
 else {
  echo 'NO RESULTS'; 
 }
 // CLOSE CONNECTION
 mysqli_close($mysqli);
?>

Ads :
Buy iPad Tablet eBook Reader on www.ebay.com
Electronics, Cars, Fashion, Collectibles, Coupons and More Online Shopping | eBay
www.ebay.co.uk | www.ebay.com.my

Wednesday 15 May 2013

How to upload file to server in android


If you are building an app that requires files to be uploaded on server you will need to follow this method. By using this method,  you will be able to upload a file from your SD Card.

We will be using httpmime-4.2.5.jar for this tutorial. You can download it from here. Extract the zip file and you will find jar file under lib folder.


  1. Create a new android project in Eclipse, and add the jar file to lib folder.
  2. Add android.permission.INTERNET and android.permission.WRITE_EXTERNAL_STORAGE in your manifest file.
  3. Use the following code :
 String address;
 MultipartEntity entity;
 File f;
 FileBody fb;
 entity = new MultipartEntity(
    HttpMultipartMode.BROWSER_COMPATIBLE);
 address = Environment.getExternalStorageDirectory()
    + "/temp.dat";
 f = new File(address);
 fb = new FileBody(f, "application/octect-stream");
 entity.addPart("file", fb);
 HttpClient httpclient = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("Your URL Here");
 
 httppost.setEntity(entity);
 HttpResponse response = httpclient.execute(httppost);
 BufferedReader bufferedReader = new BufferedReader(
  new InputStreamReader(
   response.getEntity().getContent()));
 StringBuffer stringBuffer = new StringBuffer("");
 String line = "";
 String LineSeparator = System.getProperty("line.separator");
 while ((line = bufferedReader.readLine()) != null) {
  stringBuffer.append(line + LineSeparator);
 }
 bufferedReader.close();
 return stringBuffer.toString();
 } catch (ClientProtocolException e) {
  return e.toString();
 } catch (IOException e) {
  return e.toString();
 } 
Here we use MultipartEntity from the http library to add file for uploading.
f = new File(address);
fb = new FileBody(f, "application/octect-stream");
entity.addPart("file", fb);
We select the file given by address and then we get filebody using the FileBody Class and then add it to the entity.
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("Your URL Here");
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
We create a new HttpClient and a HttpPost object, set entity and execute the reuqest.
Now android does not allow us to use network operations under the main thread, either we have to create a new thread or we use AsyncTask. You can Find the full source code here or download it here .
You can also use FTP library to uplaod the file which is better than this approach as described here.
Ads :
Buy Hard Drive, RAM, CD, DVD, USB on www.ebay.com
Electronics, Cars, Fashion, Collectibles, Coupons and More Online Shopping | eBay
www.ebay.co.uk | www.ebay.com.my

Tuesday 4 December 2012

Some useful shortcut keys for windows

We often use the mouse to do many things on our pc or laptop. Using mouse is easy but some time slow in accessing some functions. So, we have some shortcut key for many functions that windows provides.
Here is the list :
ctrl + w Closes the current window
ctrl + e
ctrl + f
Reach to the search box (Windows 7)
ctrl + r Refresh
ctrl + n Opens new copy of same window
alt + p Toggle show file preview
alt + d Direct access to address bar
alt + tab Switch windows
alt + space Open command menu
window key + up arrow Maximizes window
window key + down arrow If window is maximized, restores it
else minimizes it
window key + left arrow Move window to left
window key + right arrow Move window to right
window key + e Opens explorer
window key + d Shows desktop
window key + f Open new search window
window key + l Switch user
window key + f Open new search window
window key + x Opens windows mobility center
window key + b reach to notification area
(right side on taskbar)
window key + m minimize current window
window key + tab Switch windows
ctrl + shift + esc Open task manager
ctrl + esc / Window key Open start menu
ctrl + shift + n New folder
windows + number key Open nth item from task bar
(Window+1 will open 1st item)

Ads :
Buy Laptops and netbooks : HP, DELL, SONY, ASUS on www.ebay.com
Electronics, Cars, Fashion, Collectibles, Coupons and More Online Shopping | eBay
www.ebay.co.uk | www.ebay.com.my

Wednesday 19 September 2012

Sorting With Sound Effects

Sorting, huh.. whenever you heard about, it is always a boring topic. But what about adding a little sound effect to it.
Here are some videos showing how these algorithms work with a little sound effect. Instead of values for data sound peach is used.







And What about explaining insertion sort in form of a folk song :)

Hey, if you liked it, please click on ad below...


Ads :
Buy Apple MAC, iMAC, MAC mini on www.ebay.com
Electronics, Cars, Fashion, Collectibles, Coupons and More Online Shopping | eBay
www.ebay.co.uk | www.ebay.com.my

Monday 17 September 2012

How to change Facebook default theme

Have you ever thought how good it would be if you could change default theme of Facebook. Yes, now you can do this, and do it very easily.
You Just have to use the script provided below..
Instructions :
If you are using IE then just open Facebook and copy paste the script in address bar and press enter.
If you are using Firefox Create a bookmark button on bookmark bar with the script as loaction (To add bookmark to bookmark toolbar goto bookmarks->bookmarks Toolbar). Now open Facebook and click on bookmarked button. If you cant see bookmarks toolbar select View->toolbars->bookmarks Toolbar. This is just a test version that changes all the colors.
NOTE : you can enter name of color or hex code in prompt box. If you like it please click on the ad below.

javascript:change();
function change()
{
    var x = document.getElementsByTagName('title');
    x[0].innerHTML =  "ZZ Script | "+x[0].innerHTML;
    var col = prompt("Enter Color");
    x = document.getElementsByTagName('div');
    var i=0;
    while(i < x.length)
    {
 x[i].style.backgroundColor=col;
 x[i].style.borderColor=col;
        i++;
    }

    x = document.getElementsByTagName('li');
    var i=0;
    while(i < x.length)
    {
 x[i].style.backgroundColor=col;
 x[i].style.borderColor=col;
        i++;
    }
    x = document.getElementsByTagName('ul');
    var i=0;
    while(i < x.length)
    {
 x[i].style.backgroundColor=col;
 x[i].style.borderColor=col;
        i++;
    }
    x = document.getElementsByTagName('a');
    var i=0;
    while(i < x.length)
    {
 x[i].style.backgroundColor=col;
 x[i].style.borderColor=col;
        i++;
    }
    x = document.getElementsByTagName('span');
    var i=0;
    while(i < x.length)
    {
 x[i].style.backgroundColor=col;
 x[i].style.borderColor=col;
        i++;
    }
    x = document.getElementsByTagName('input');
    var i=0;
    while(i < x.length)
    {
 x[i].style.backgroundColor=col;
 x[i].style.borderColor=col;
        i++;
    }
}
Ads :
Buy Amazon Kindle Fire, Microsoft Surface, Apple Ipad on www.ebay.com
Electronics, Cars, Fashion, Collectibles, Coupons and More Online Shopping | eBay
www.ebay.co.uk | www.ebay.com.my

Sunday 16 September 2012

How to play Nintendo games on your computer



Ever wondered how to play this old Nintendo games on your computer !!
Yes, you can play these games on your computer using emulators. An emulator is hardware or software or both that duplicates (or emulates) the functions of a first computer system (the guest) in a different second computer system (the host), so that the emulated behavior closely resembles the behavior of the real system. (Wikipedia)
So to play these old games you can use different emulator. One of them is jnes (links at bottom of this post).
Once you have downloaded jnes extract it and run the executable file. From file browsers nevigate to games folder emulator directory select super_mario_bros.nes file and the game will start. goto options->input and change the keyboard setting. If you want to play more games google for .nes file for your game. Not only Nintendo you can also use emulators for PSP, PS-II, PS-I, XBOX, etc.
Here are some links from where you can download .nes files :
www.freeroms.com
www.nesfiles.com
www.romhustler.net
Download Jnes

Click here



Ads :
Buy Smart Watches on www.ebay.com
Electronics, Cars, Fashion, Collectibles, Coupons and More Online Shopping | eBay
www.ebay.co.uk | www.ebay.com.my

Saturday 15 September 2012

Useful Run Commands

cmd : Used to open command prompt.
msconfig : Opens configuration windows. You can edit startup programs, boot configuration.
msinfo32 : Provides you full system information like hardware resources, system components and software environment.
regedit : Opens registry editor.
sysedit : Edit system configuration. (USE WITH CARE !!)
winver : Shows you windows version and other info.
compmgmt.msc : Opens Computer management window.
devmgmt.msc : Opens Device manager.
diskmgmt.msc : Disk management Tool.
dfrg.msc : Disk defragmenter tool.
fsmgmt.msc : Manage Shared folders.
gpedit.msc : Group policies editor.
lusrmgr.msc : Opens Local users and groups.
perfmon.msc : Opens Performance monitor.
secpol.msc : Opens Local security settings.
services.msc : Shows Services on machine.

See Also : How To Triple Boot (Windows XP/Windows 7/Ubuntu)
Ads :
Buy Wristwatches, Pocket Watches, Ring Watches on www.ebay.com
Electronics, Cars, Fashion, Collectibles, Coupons and More Online Shopping | eBay
www.ebay.co.uk | www.ebay.com.my