Thursday, April 21, 2011

PHP Dynamic Prepared Statement Example

Prepared statement is currently one of the safest techniques to manipulate your database. The only problem is SQL statement has to be compiled first and then you have to populate/bind your parameters/values.

Here is how to create dynamic prepared statement in PHP. This example assumes you have setup database connection using PDO.

Requirement:
$host = "...";
$username = "...";
$password = "...";

$dbh = new PDO("mysql:host=$host;dbname=database_name", 
$username, $password);
Last line creates a PDO object.

1. Declare your initial SQL statement for selecting data:
$query = "SELECT * FROM tblExample WHERE 1=1";
Notice there is 1=1 after the WHERE clause this will help you avoid deciding which parameter goes first because you will have to use AND to combine other parameters later on.

2. Create an empty array for storing your binding name and parameters:
$list_array = "";

3. Now, perform a check on a variable to see if it qualifies to go into your SQL statement (this example receives values from a submitted form using POST method):
if(!empty($_POST["userName"]))
{
 $query .= " AND user_name = :userName";
 $list_array[":userName"] = $_POST["userName"];
}
What the heck is this? If user doesn't fill out his name, the field userName will return empty which is what we're checking for. If the field userName is not empty, we append (add on the end) more parameters to the SQL statement with a bind name. Second line inside the IF statement uses our previously created array to store bind name as KEY and value as VALUE. Repeat this step as many times as you like.

4. Close your SQL statement with a parentheses:
$query .= ")";

5. Compile SQL statement using prepare() method of PDO object and store result in a variable:
$statement = $dbh->prepare($query);

6. The fun part. Cycle through your array of binding names and values to bind parameters with your SQL statement:
if($list_array != "")
{
 // bind parameters to values
 foreach($list_array as $key => &$value)
 { 
  $statement->bindParam($key, $value);
 }
}
IF condition checks if there is any data in the array. In case user doesn't enter any information your SQL statement will just return everything from the specified table, in our case tblExample. Inside the IF statement, foreach loop is used to cycle through each item of $list_array and binds parameters using $key as a KEY and $value as VALUE.

(OPTIONAL) - You can print your SQL statement to see what it looks like before it gets executed for testing purposes. If userName field is entered the SQL statement will look like this:
SELECT * FROM tblExample WHERE 1=1 AND user_name = :userName"
:userName will be replaced with what user actually typed in the form.

7. Run your SQL statement:
$statement->execute();

8. Get your results and close database handle:
$result = $statement->fetchAll();
$dbh = null;

That's about it. I figured this out while writing a search function based on user input which is why I used a SELECT statement.

Let me know if you have any questions and I'll be glad to help you.

Friday, April 8, 2011

ASUS Eee on AMD Brazos technology

ASUSTek Computer added few more netbooks in their collection. New netbooks ASUS Eee PC are the first of their kind, equipped with AMD Brazos and AMD Fusion.


ASUS Eee PC 1015B model has 10.1-inch screen (1024 x 600 resolution), Windows 7 Starter operating system, has single core AMD C-30 processor with 1.2 GHz frequency, and AMD Radeon HD 6250 video card. Also, netbook has 2 GB virtual memory, up to 500 GB storage capacity, Wi-Fi 802.11b/g/n, Bluetooth module, 0.3-mega pixel web-camera, built-in card reader, and USB 3.0.


ASUS Eee PC 1215B characteristics:
  • 12.1-inch display screen (1366 x 768)
  • Windows 7 Home Premium
  • Dual-core AMD E-350 1.6GHz
  • Integrated AMD Radeon HD 6310
  • Up to 4 GB virtual memory
  • Up to 500 GB storage capacity
  • Wi-Fi 802.11b/g/n adapter
  • Bluetooh module
  • Built-in 0.3 mega-pixel web camera
  • Built-in card reader and USB 3.0

AMD Radeon HD 6790 has increased ROP

Potential miss-communication between AMD and manufacturing company caused new line of video cards Radeon HD 6790 to have increased number of ROPs. This video card is designed to have only 16 out of 32 active blocks of rasterization in 40 nm technology Barts.


While this, so called, problem is a great advantage for end consumer it's very frustrating for AMD because it slows down line of production for the company.

The "problem" has been recognized by TechPowerUp when their GPU-Z utility displayed 24 ROP instead of 16. Initially, testers thought their utility encountered an error or miss-calculated results but in reality Radeon HD 6790 actually had 24 active ROP. TechPowerUp contacted AMD to confirm this information and it is official that every video card has 24 blocks of rasterization.

This isn't the first time AMD is having these problems. Few Radeon HD 4830 video cards had 80 less processors than expected. Another one, Radeon HD 6850 had 1120 active shader processors instead of 960.

Thursday, April 7, 2011

Media laptop from MSI: MSI FX420 and MSI FX620DX on Sandy Bridge

Micro-Star International (MSI) is releasing new line of portable laptops, MSI FX420 and MSI FX 620DX built on mobile Intel Huron River platform.


F series laptops look very sleek and have great performance. Laptops have Intel Sandy Bridge processors, NVIDIA or AMD video card, THX TruStudio Pro sound system, Blu-ray or DVD Super-Multi, and USB 3.0 port. Cinema Pro is used to enhance video and audio quality in movies. ECO Engine is responsible for efficient use of power. More images and details below:


The only question remains now is where and when is this product going on sale?!?!

Monday, April 4, 2011

AMD Radeon HD 6790: Barts LE

Advanced Micro Devices (AMD) officially announced the release of Radeon HD 6790 for sale, which should be a good competitor for NVIDIA's GeForce GTX 550 Ti.


This model is built on PCI Express 2.1 x16 and is covered with black casing, it also uses double-layered cooling. The core of this marvelous piece of beauty is built on Barts LE chip with 800 multi-threaded processors, and 40 textured modules (TMU). Theoretically, Radeon HD 6790 reaches 1.34 trillion operations in half a second. This graphics card has 1GB of GDDR5 memory with 256-bit interface and through rate of 134.4 GB/s. Frequency of the video card is 840/1050 MHz. Level of TDP doesn't exceed 150 Watt during load and 19 Watt on idle. Back panel is equipped with ports, like DVI, HDMI 1.4a and few MiniDisplayPort 1.2.



Accelerator supports DirectX 11 Shader Model 5.0 and multi-channel 7.1 HD Surround Sound. Also, supports technologies: AMD HD3D Technology, AMD Eyefinity Multi-display Technology and AMD CrossFireX Multi-GPU Technology.



According to AMD's test Radeon HD 6790 is faster and better than GTX 550 Ti. Look at the picture below.


The original version of this video card Radeon HD 6790 PowerColor is available for sale at various online retailers for $150.

Sunday, April 3, 2011

I-O DATA - three new storage devices with USB 3.0 interface

I-O DATA HDCA-UT model is enclosed using black case with measurements 185 x 120 x 39 mm, weighs 1.1kg and is available in 1 or 2 terabytes (TB).


I-O DATA HDPC-AU weighs 350 grams, comes in five different colors with measurements 75 x 112 x 14 mm. Available in sizes of 320, 500, 640 or 750 GB.



I-O DATA TB-XT - case is a combination of blue and silver with measurements of 18 x 69.6 x 8.6 mm, weighs 19 grams. This model is available in 8, 16 and 32 GB.

Windows Home Server release in April

Microsoft representatives announced the release of Windows Home Server 2011. Operating system is ready, fully functional and ready for deployment. Microsoft Developer Network subscribers will receive access to new OS before everyone else.



Windows Home Server 2011 will be on sale starting May of this year. Unlike the previous version, this one supports 19 different languages, including Chinese, English, French, German, Italian, Spanish, Japanese, Polish, Portuguese, Russian, Sweden, Turkish, and others. Windows Home Server 2011 supports wireless transmission of multimedia data DLNA 1.5. There is still debate whether to include additional Drive Extender application which allows users to combine multiple data storage devices into one.

Grim Dawn - independent Diablo clone

Independent studio Crate Entertainment published a preview of RPG game Grim Dawn.


This video shows a preview of game concept for Grim Dawn. The game resembles Diablo, especially the second project. The only main different between these two games is Grim Dawn has a lot more blood effects than Diablo.

Currently Grim Dawn is only in its development stage but so far it looks like a great game.

WinMount 3.5.0331 - archive management ZIP/RAR

WinMount has updated their application which is used to work with .zip and .rar files. Instead of extracting/unpacking files to find what you need simply mount your archive as a virtual drive and access all of its information.


It's much faster than having to wait while a gigabytes of information unpack, in result having duplicate content on your computer. WinMount supports more than just archives, here are some other formats: ISO, CUE/BIN, CCD, BWT, MDS, CDI, NRG, PDI B5T m ISZ. Also, WinMount is capable of working like an emulator for CD/DVD drive.

Last updated has fixed numerous bugs.

Developer: WinMount International
Distribution: shareware, $50
Operating System: Windows All
File Size: 3.48MB
Download from here.

Ubuntu 11.04 beta version released

Ubuntu team has announced the release of first beta version towards the big release of mega operating system, called 11.04 and known as Natty Narwhal.

During the development stage of Ubuntu 11.04 programmers spent enormous amount of time on user interface, performance, stability and security of OS. The core of Ubuntu 11.04 is updated with Linux 2.6.38 and a single all supporting platform Unity. Operating system comes with a package of updated application, such as: LibreOffice 3.3.2 (substitution for OpenOffice.org) as well as Ubuntu Software Center.


Ubuntu 11.04 Beta 1 is available for download from its official website. The release date for final modified version of Ubuntu is planned for April 28, 2011.

Keep in mind, with the release of final version Ubuntu the cycle will conclude at 9.10. Starting April 29, 2011 Ubuntu platform will no longer be updated for improvement or any kind of bug fixes. Users are advised to update their current version of Ubuntu using instructions provided on official website.

New features and interface Chrome 12 and Firefox 5

Google is actively working on their web browser Chrome. Mozilla is also forcing the release of final version. This summer users will finally get Chrome 12 as well as Firefox 5. These version will include: increased productivity, fixed bugs, and optimization. Also, interface changes.

Recently Google announced a compilation of Chrome browser for developers version 12.0.712.0. Among all the new features Chrome has acquired few stand out the most. One of these features is allowing the user to select multiple tabs/windows by holding the Control (Ctrl) key, then use can perform various tasks on all selected items, such as: close tabs, restart tabs, relocate tabs, etc. For newly opened tabs (without a page) there is access for mobile application for smart phones.


While this is happening Mozilla will make changes to the recently released Firefox browser version 4. Main changes will include the interface for Firefox 5. The release of Firefox 5 will happen a lot faster than version 4, approximately less than four months.



On the picture below you'll see a template for the new interface which has includes new design and a new way of managing bookmarks, which supports multiple accounts.

The feature you see above will allow user to log into Facebook, Gmail and other resources without having to open another tab or windows browser. Users will be able to switch accounts in the same window using that tiny icon. Firefox 5 should be released in the end of June.

Mozilla took over a year to develop Firefox 4. In the first day of releasing version 4 approx. 8.75 million copies have been downloaded, which set a new record comparing to Firefox 3 back in 2008 (8 million in 24 hours).

Saturday, April 2, 2011

Crunchy Logistics equipped the first multi-touch bar in U.S.

Company Crunchy Logistics published a video in which they show the first 8.5 m long bar stand, the top of which is covered multi-sensor display. Sensor panel accepts commands from unlimited number of points.


This spectacular display will lighten up any modern interior. Control panel currently supports a few effects which are triggered when someone or something touches the panel. Effects are, fire, flowers, and flames. This multi-touch sensor screen is very unique because it picks up objects as well, such as: apples and glasses. Unfortunately, there is no information whether this product is going to mass produced. Multi-touch bar received a name "mtBAR". The same concept has been previously presented in Europe under the name iBar.


Chieftec Nitro 88+: power supply of 80Plus Silver class

Company Chieftec presented their new power supply, called Nitro 88+, which differs by its cable connections and 80Plus Silver certification. Chieftex Nitro 88+ is aimed for use in gaming systems.


Nitro 88+ power supplies include one line of +12 V, 140-mm fan and followed ATX 12V 2.3 standard. Announced time frame of operation is 100 thousand hours.

This line of power supplies includes 650, 750, 850, and 1000 Watt, which are ready for order. Prices follow in the same order: 112 Euro, 120 Euro, 159 Euro, and 199 Euro.

MSI X-Slim X370 - thin laptop with AMD Brazos

Micro-Star International (MSI) has officially announced the release of thin portable laptop MSI X-Slim X370, which implements the use of AMD Brazos platform and AMD Fusion concept.


Laptop weighs at 1.4kg (including 4-element battery) and measures at 324 x 227 x 22.8 mm. Also, laptop uses Windows 7 Home Premium Windows operating system and:
  • Accelerated processor AMD E-350 and AMD E-240 (both have 1.6GHz frequency)
  • Collection of AMD A50M micro-systems
  • AMD Radeon HD6310 graphics card
  • 13.4-inch display with 1366 x 68 resolution
  • Up to 4GB virtual memory
  • Up to 640GB hard drive with 5400 RPM
  • Integrated 1.3 mega-pixel camera
  • Gigabit Ethernet network card
  • Wireless adapater Wi-Fi 802.11b/g/n
  • Bluetooth v2.1 + EDR module
  • SD/SDHC/SDXC/MMC slot
  • Ports for D-Sub and HDMI, 2 USB 2.0 ports, and input for microphone and headphones
  • 4 or 8 element battery
Price of MSI X-Slim X370 is not yet available.

Continuance batteries with USB output

Four Asian designers presented a new universal look on batteries; combining USB plug with normal triple-A batteries. The name given to this innovation is Continuance.


Using USB plug batteries may be used for their direct reason - to power other devices, such as: flash lights, alarm clock, phones, etc. Placing a USB plug into a battery makes each unit very expensive to acquire so Continuance designers decided to make these batteries rechargeable. This is amazing solution will save customers money with only down-side is that each Continuance owner will have to carry a USB cable for his device specifically.


Friday, April 1, 2011

How to delete/remove defender virus from Windows XP

Defender virus - isn't actually a virus and it doesn't harm your computer it just prevents you from using your computer. Defender is a small application written for marketing purposes for users to purchase anti-virus software from that advertising company.

Once you're infected with this virus every window and application you had opened will be closed, access to any installed applications will be denied because defender.exe will inform you that application you're trying to run is infected with a virus.

Don't be alarmed there is a way out. Just follow these steps.

1. Restart your computer through Start->Turn off Computer>Restart or hard reboot using the button on your computer case. In case you don't have a restart button on your case (as some new cases no longer have it) you can press and hold the Power button until your computer shuts down. Once computer has shut down just press Power again to boot it up.

2. Enter Safe Mode. Depending on your computer manufacturer how you enter Safe Mode may differ. To enter Safe Mode, press and keep pressing F8 button on your keyboard (some computers have this as F10 or F12) once you performed Step 1, which is restart your computer.

3. Select Safe Mode from the Menu and press Enter. Wait for computer to load fully. Once you get to user login screen you can select your username which you usually use. Don't use Administrator account unless your own account doesn't work. Safe Mode will disable all normal programs or services to load; only the necessary ones for the Windows to operate will be working.

4. Open Control Panel, open Folder Options icon and select the View tab. In the Hidden files and folders section select "Show hidden files and folders" and click OK. You can close control panel now.

5. Open My Computer, then C: drive and follow to this path: C:\Documents and Settings\[your-account]\Application Data\. In this folder find and delete the file defender.exe. Close all open windows.

6. Press Start->Run. In the prompt dialog type "msconfig" (without quotes) and click OK. A new window will open, when that happen select the Startup tab (second last one).

7. Now, find defender in the Startup Item column and uncheck it. Then, press OK and when prompted to restart press Restart. Let your computer load normally. The defender virus should not load or pop-up any more.

Hopefully this article will help you free your computer from defender virus and allow you to proceed with your daily tasks.