microsoft

Connecting to SQL Azure with PHP

2

To start, I would like to first say that although many PHP developers usually recommend MySQL as the accompanying database for PHP, it is not difficult to interface PHP with other databases such as SQL Azure, Microsoft’s cloud-based relational database offering.

PHP connects with SQL Azure in a similar manner as how it does with Microsoft SQL Server, ie through an interface known as the Open Database Connectivity (ODBC), which is actually the standard software interface for accessing databases. Each platform and database has its own implementation following the ODBC standard but for this tutorial, I’ll focus on PHP.

There are a few ways to connect your php site to MS SQL but the 2 main approaches are as shown in Figure 1.0.

1. Using the “php_mssql.dll” php extension requiring MS SQL Client Tools installed (Figure 1.0, right column).
2. Using the “sqlsrv” driver (“Microsoft Drivers for PHP for SQL Server”) requiring MS SQL Native Client installed (Figure 1.0, left column)


Figure 1.0

I will be using the 2nd approach for this tutorial because it supports both PHP 5.2 and 5.3, unlike the 1st which is not available for PHP 5.3.

Microsoft Drivers for PHP for SQL Server
As of 1 February 2011, the latest version of the driver is version 2.0.1 (30 November 2010).
You can grab it from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=80e44913-24b4-4113-8807-caae6cf2ca05
Once you have installed the drivers, you should see the following in the installation directory:


Figure 2.0

We will be using the “php_sqlsrv_53_nts_vc9.dll” library for this tutorial.
• “php_sqlsrv” –> Driver name
• “53” –> PHP 5.3
• “nts” –> Non-thread safe (The PHP FastCGI Handler of IIS handles thread-safe operations for PHP, use the non-thread safe version to reduce performance issues)
• “vc9” –> Library compiled using VS 2008, use vc6 (VS 6) if PHP is running on Apache
Configure PHP
1. Copy “php_sqlsrv_53_nts_vc9.dll” into the “ext” folder of your php installation directory.
2. Edit the php.ini to include the library


Figure 3.0


Microsoft SQL Server 2008 R2 Native Client
In order for the PHP for SQL Server Drivers to work, the necessary SQL Server ODBC drivers must be installed on the web server.
The version of the ODBC driver needed for SQL Azure comes with the SQL Server 2008 R2 Native Client.
You can grab it from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ceb4346f-657f-4d28-83f5-aae0c5c83d52

PHP Syntax
After all the preparation and configuration, here comes the actual thing -> Coding!
This tutorial showcases how to do simple CRUD (Create, Retrieve, Update, Delete) commands.
1. Connect to Database:

$serverName = “servername.database.windows.net”;
$connInfo = array(“UID”=>”username@servername”,
“PWD”=>”password”,
“Database”=>”databasename”);
$conn = sqlsrv_connect($serverName, $connInfo);

2. Insert data to Database (taking data from a html form text field):

$comment = $_POST["txtComment"];
$comm = “INSERT INTO commentsqlazure (commentContent) VALUES (?)”;
$stmt = sqlsrv_prepare($conn, $comm, array(&$comment));
$result = sqlsrv_execute($stmt);

3. Update data in Database:

$Id = $_POST["txtUpdateId"];
$comment = $_POST["txtUpdateComment"];
$comm = “UPDATE commentsqlazure SET commentContent = ? WHERE id = ?”;
$stmt = sqlsrv_prepare($conn, $comm, array(&$comment, &$Id));
$result = sqlsrv_execute($stmt);

4. Remove data from Database:

$Id = $_POST["txtRemoveId"];
$comm = “DELETE FROM commentsqlazure WHERE id = ?”;
$stmt = sqlsrv_prepare($conn, $comm, array(&$Id));
$result = sqlsrv_execute($stmt);

5. Retrieve data from Database:

$comm = “SELECT id, commentContent FROM commentsqlazure”;
$stmt = sqlsrv_query($conn, $comm);
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))
{
echo $row["id"].” “.$row["commentContent"].”
“;
}

6. Close connection and release resources:

sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

You can download the project file from here.
http://cid-29f099c37b76ca59.office.live.com/browse.aspx/Blog/Code%20Guide/SQL%20Azure?uc=1

Please take note that you have to change the Server Name, Username, Password at the connection string to make this work. You should run the following script to the table first.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/SQL%20Azure/SQLAzureConnection.sql

Credit to Luke Ng.

Connecting to SQL Azure with ASP.NET

0

Recently, I have been working with Windows Azure and SQL Azure for my new project and because of this, a good amount of developer friends came to me and wanted me to share more about it hence I decided to write it down as a blog post for anyone who is interested to know about it.

What is SQL Azure?
SQL Azure is Microsoft’s Relational Database offering on the Cloud. It is build from the foundation of SQL Server It helps to actually ease the provisioning and deployment of many databases. It is easily scalable per se.

This blog post is going to show you how easy is it for you to connect to SQL Azure, it actually works the same way as a normal SQL Server Connection, the main difference is the connection string. The username is your username setup at SQL Azure @ Server name. You can download the full sample project with CRUD ( Create, Retrieve, Update, Delete ) at the end of this post.

///
/// Connection to SQL Azure Database
///
public void ConnectToDatabase()
{

//Connection String
//data source=SERVER URL;
//initial catalog= Database name;
//User ID=User ID @ Server Name;
//Password=Password;
string connectionString = “data source=quxm9ku7nz.database.windows.net;initial catalog=fiveaboutme;User ID=guohong@quxm9ku7nz;Password=*****;”;
if (conn.State != ConnectionState.Open)
{
conn.ConnectionString = connectionString;
conn.Open();
comm.Connection = conn;
}
comm.Parameters.Clear();
}

You can download the project file from here.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/SQL%20Azure/SqlAzureConnection.zip

Please take note that you have to change the Server Name, Username, Password at the connection string to make this work. You should run the following script to the table first.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/SQL%20Azure/SQLAzureConnection.sql

How to use Back Button on Windows Phone 7

1

Credit to Steven, http://www.sticapac.com for allowing me to post this up on my blog.

Recently, I worked on an app for the Windows Phone 7 platform and submitted it to the marketplace for certification. I’ve learnt many things and gained many insights after going through this process and would like to share one of these with you, developers and potential developers of the Windows Phone 7 platform.

Throughout this post, I will be making references to the official Windows Phone 7 Application Certification Requirements document (WP7ACR) which can be downloaded athttp://go.microsoft.com/?linkid=9730558.

Under Section 5.2.4 of the WP7ACR, clause a, it is stated that:

Pressing the Back button from the first screen of an application must exit the application.

Developers who are creating apps with multiple pages must give special attention to this clause because pressing the back button automatically brings the user to the previous page, regardless of whether the user is at the first screen or not. Consider the following example:

In this app, there are 2 pages. Page1 goes to Page2 via a button with the following logic:

NavigationService.Navigate(new Uri(“/Page2.xaml”, UriKind.Relative));

Page2 goes back to Page1 via a button with the following logic:

NavigationService.Navigate(new Uri(“/Page1.xaml”, UriKind.Relative));

Each time that line of code is executed, it is actually creating a new instance of the page defined under the new Uri. Therefore if the user navigates in this manner:

  1. User starts the app.
  2. User navigates to Page2 via button.
  3. User navigates to Page1 via button.

At this point in time, the user is at the first page of the application. If the user presses the back button, he will be brought back to Page2 instead of exiting the app, which is wrong and will result in a failure of the certification process.

There is no API in the Windows Phone 7 SDK similar to the Application.Exit() function found in the average C#.NET Windows Forms application. For this reason, we must overcome this problem by navigation by page hierarchy. That is to say, when the user navigates from Page2 to Page1 via the button, instead of treating Page1 as a new page, the developer should instead use this line of code for the navigation purpose from Page2 back to Page1:

NavigationService.GoBack();

By doing this, the developer is essentially coding the button to function exactly like what the back button does on the Windows Phone. In this way, the app will always exit when the back button is pressed on the first page because the first page is always the only record under the action history when the user is on the first page. The diagram will then look like this:

Therefore we have successfully adhered to Section 5.2.4 of the WP7ACR, clause a. This is how we can effectively use the Back button and pass certification for functions relating to the back button.

Windows 7 Workshop

0

Met YangLin, Pratibha, Eugene and Alex there while I attend the Windows 7 Development workshop at SMU organised by SG Acad Team, MS Singapore. I have been following Jocelyn Villaraza‘s blog but never had a chance to see her in action and today, finally, i had. Pretty good presentation done by her.

I am gonna rewrite one of her guide for my school’s bootcamp. Hope to get it done when I am free next week ( After Monday ). I never knew that program was so cool.

Going to teach wushu tomorrow morning!

One whole day

0

Yawnz, have been doing ECSA for one whole day… not one subject which I am most pleased with..

I want to do some bits of ENCM later at night! So excited about the Windows 7 development workshop tmr at SMU.

Developing application on Windows Mobile Platform

1

Chirs Chin, Developer Marketing Director, Microsoft Singapore came to MSP (Microsoft Student Partner) meet on Saturday to give us a quick talk on Windows Mobile 6.5 (http://wmdevasia.wordpress.com/2009/08/22/aug-22nd-2009/), abit on Windows Mobile Marketplace and asked us to submit applications for certification if we can. Certainly, he got me excited and right after my exam on Wednesday afternoon, I begin to develop my first Windows Mobile Application. As a student, we should try everything. :p

I posted it on my facebook and twitter and it seems like it gotten some attention from my friends. Some of my friends, my classmates and friends outside, asked me whats the difference in developing a client-side application and mobile application, I will say beside the idea that should be generated is a bit different, the rest are the same. I will be covering this later.

On Thursday night, Microsoft Singapore has a Mix-It-Up event and the speaker is Chris as well. Went down and listen what he has to present and what others are presenting. A group of students and 2 companies presented their product. I am really impressed by what the students and HNL had done. =)

Let me point out some of the differences here.

1. The normal application we are developing on VS08, we normally use .Net framework 3.5 but for a windows mobile application, we use .Net Compact framework 3.5 ( http://en.wikipedia.org/wiki/.NET_Compact_Framework )

2. Can we develop a silverlight application on Windows Mobile since silverlight is cross platform? At the moment, its a no. I believe something is coming out soon though ( After doing a search on bing, http://www.brighthand.com/default.asp?newsID=13870 )

3. I am developer, what is the link to Windows Mobile Marketplace?

http://developer.windowsmobile.com/Marketplace.aspx?wa=wsignin1.0

4. Where can I find applications which I can buy for my Windows Mobile phone?

http://www.microsoft.com/windowsmobile/catalog/cataloghome.aspx

5. I want to start developing. Where is the SDK?

http://www.microsoft.com/downloads/details.aspx?familyid=06111A3A-A651-4745-88EF-3D48091A390B&displaylang=en

You might want to have a look at the toolkit as well

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=20686a1d-97a8-4f80-bc6a-ae010e085a6e

Hopefully my application I am developing will be a success though I am facing some difficulties now. =)

Follow me at @limguohong

Microsoft Security Essentials Beta

1

Recently, to be more extact, 23th June 2009, Microsoft released the beta of Security Essentials which was the previously Windows Live One Care.

Allow me to quote this from wikipedia,
[quote]Microsoft Security Essentials (codenamed Morro) is an upcoming gratis antivirus software created by Microsoft that will provide protection from viruses, spyware, rootkits, and trojans for Windows XP, Windows Vista, and Windows 7.[3]

Amy Barzdukas, senior director of product management in the online services division at Microsoft, said: “This new, no-cost offering will give us the ability to protect an even greater number of consumers, especially in markets where the growth of new PC purchases is outpaced only by the growth of malware.” [3]
[/quote]

I will say that the installation is very smooth and the virus scanning relaly run quietly at the background. These are some of the screenshot which I have taken while installing.

Windows 7

1

Windows 7

Before I start my LONG post on Windows 7 at this late hour ( 4.10am ), this are the information you might want to know

- Did clean install on a partition which previously has Windows 7, build 7077
- Installing Windows 7, build 7100 ( RC1 )
-This is my computer specs,
250gb space
4gb ram
Intel Core 2 Duo 2.40 GHz processor
I am installing a 32 bit version of build 7100.

This is not my first time installing Windows 7 on my laptop.
—————————————————————————–
The experience was really great! Let me tell you it took me how long to install the windows. Only 36 minutes and 37 seconds.

This is the breakdown timing of my installation

00.00.00 – On computer with installation disc in drive
00.59.46 – Loading File
01.39.58 – Starting Windows – Set Up
02.32.40 – Installing Windows
17.57.50 – 4/5 Installation completed, Computer restart
19.35.51 – Starting Service
32.15.07 – Installation completed, Computer restart
33.22.51 – Preparing for the first time use
34.09.62 – Set Up
36.37.61 – First Boot into Windows 7

It only took me 36 minutes. 36 minutes 37.61 seconds to be extact. I mean, wow…. its only 36 minutes and whats more, I did not had any big issues when installing the OS.

Most of my readers are not very technical person so some of you might be asking what is Windows 7? Basically, it is a new Operating System. It is the next one after Windows Vista. :)

What are the differences?
I am unable to tell you ALL the differences between its really a big advancement especially in speed. The speed of the OS is really good!

Pictures speak more than a thousand words. Have a look. :)


The first screen you will see after your installation.


See mini screen capture of the running program and be able to navigate to it. You don’t have to worry about spending time to find your lost tabs.


Bottom right of the page is show desktop. Upon hovering over it, you can see what the desktop is like. Likewise for the mini screen capture, upon hovering over it, you can see what the program is like.


Shortcuts to functions of a program and even links to the frequently visited page.


Does this look like paint? Yes, it is paint!


Dock your windows. Its easier for you to compare two documents now. Instead of spending 30 seconds of your life trying to resize 2 document windows so that you can compare. You just have to drag the windows to the extreme sides to make it dock. ( Like the image above )


Moving from GUI to NUI ( Natural User Interface ). You can use your hand and write to communicate with your computer.


Customize your Notification Area ( What you see at the bottom right ) now!

Did I mention that I am using Windows 7 for most of my work and school work?

I am very excited!!! Later, I will be going to watch a Imagine Cup’s presentation and award ceremony and one of the agenda is ……

by MATTHEW Hardman! Cool guy, met up with him in MIC when we are recording the Live@Edu video. I happen to bring my brother, MATTHEW Lim there and yea. They are playing Guitar Hero together. A working guy and a young boy.. weird combo but yeah! ^.^

Go and try it out!

http://www.microsoft.com/windows/windows-7/download.aspx

Will be posting more soon. Kinda late. Time to sleep, need to rush some school’s project later in the day and finally meet up with all the MSPs. Long time since we met as a team at Microsoft, eh HAHA. I wonder if I will get the chance to talk to Neng Giin, some things I need to ask him. Umm.

Launch of Dreamspark

0

Tomorrow is a long long day

0

Tomorrow is a long long day

——————————-

Anyway, on Thursday, a few of our Student Partners went to Microsoft to experience the Microsoft Surface ( Microsoft Site ) [Microsoft Surface]. The only thing i can share, its very very cool. =)

Went straight to training after that and something very terrible happen. I was doing Wai Bai Lian and suddenly my right knee gave way and I fell down. The next thing I know is that I cant even stand up and walk liao. I don’t know what happen. Its still very pain till now. I cant even walk properly now.

Guess I will have a long break from wushu liao. Very long break.

Go to Top