Sunday, March 06, 2011

database connection with mysql



Step 1 Check the configuration
To smooth our programming later then the first thing we should do is check the configuration by typing the phpinfo (). To do this you need to create a simple php file that calls the function phpinfo (). Consider the following code:




Write the code in notepad and save it as info.php and place it in the htdocs folder. Then open a browser and type localhost / info.php

Consider the system configuration, especially on the MySQL because this part is very important to know because if this part does not exist we would not be able to work without MySQL.



Step 2 Create Database
In this tutorial I will use the MySQL database named test with a table named user. Look at the code below:

CREATE DATABASE if NOT EXISTS `test`;
USE test;

CREATE TABLE `user` (
`id` int(3) NOT NULL auto_increment,
`user` text character set latin1 NOT NULL,
`pass` text character set latin1 NOT NULL,
`nama` varchar(50) character set latin1 NOT NULL default '',
`status` text character set latin1 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=29 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=29 ;

INSERT INTO `user` VALUES (1, 'admin1', 'rahasia1', 'Nuzuli', 'user');
INSERT INTO `user` VALUES (2, 'admin2', 'rahasia2', 'Fitriadi', 'admin');Langkah 3 - make conection database



As his case with other programming that uses a database, the first thing we must do is connect to the database server. Connecting to MySQL database in PHP requires some information that is:

* hostname
* database username
* password
* database name

To connect to a database first you will connect to the MySQL database and in the next step you must select the database to be used. Remember if we fail then the connection we will not be able to proceed to the next script. Consider the following code:
Code:

$host = "localhost";
$user = "nama_username";
$pass = "tentu";
$db = "tentu";

$koneksi=mysql_connect($host,$user,$pass) or die ("koneksi ke database gagal") ;
$koneksi_database= mysql_select_db($db,$koneksi);

Function mysql_connect () is to establish a connection to MySQL server and if the connection is successful then the next step we can choose the database with the command mysql_select_db ().

Step 4 - Retrieve data from database
Now it's time to make something more interesting. For example, let's try to retrieve data from user table in database test. To do this make a connection to the database and select database test. The next step is to create SQL queries - in this case a SELECT statement - to the database. Now try to get all records from MySQL. SQL statement for this are:

$ get = mysql_query ("SELECT * FROM user");

Now after selecting the table, then how is a way to display the contents of that table? How to use the following code:

$get = mysql_query("SELECT * FROM user");
While ($row=mysql_fetch_object($ambil)) {
$name = stripslashes($row->nama);
Echo "$name";
}
?>

In the above code, I used to take mysql_fetch_object SQLnya results of the query so that the resulting rows will be defined as an object. We also can use other functions such as the following:
1. mysql_fetch_assoc () - Ambil hasil baris sebagai array asosiatif
2. mysql_fetch_row () - Ambil hasil enumerated baris sebagai array
3. mysql_fetch_array () - Ambil hasil baris sebagai array asosiatif, array numerik, else twice

The above code will display all existing data in the user table. How can if we want to display some data alone? We will use the limit to limit the number of display data and let a more regular basis we will use the order by to sort the data based on the ASC (az) or DESC (za).

$ get = mysql_query ("SELECT * FROM user ORDER BY name ASC limit of 0.2");
Basic PHP and MySQL Programming

As we already know about web programming using the database will be able to create a dynamic website content. Examples of what we can see for example the online registration application or news on news websites are kept updated every second.

One website that dynamic programming is to use PHP and MySQL database. Why PHP using MySQL database? Actually use the MySQL database is only because of habit. In addition to MySQL we can also use PostgreSQL, MS Access, Oracle, etc..

In this section I will try to explain how to use PHP and MySQL to create dynamic content and of course I just explain the basics in advance to avoid excessive hehe.

in this case I use the xampp php 5 if you can not please fetching in www.cnet.com search on the search form with the name of xampp 1.7.3

how to make LAN network


in this post, I will discuss about how to create a network (LAN) with 2 small computer using UTP cable. For that you need to prepare the UTP cable and RJ-45 Jack is already installed and the network card in each computer. Normally computers are now equipped with Lan Card on the computer motherboard. If no you can buy it at a computer store along with UTP cable and RJ-45 Jack.
If only connect 2 computers, you do not need a hub or switch. However, the cord is slightly different configuration. If you create a network for 2 computers without using a hub or switch, the configuration used is immune from Cross cable. Conversely, if use traditional a hub or switch, to create a network of more than 2 computers, the configuration of the cable wire used is Straight. Ok I just discussed about how to create a network (Lan) for connecting 2 computers. Beriikut steps:
1. Plug the UTP cable that is configured with a cross cable to the LAN port of your first computer card.
2. If you are using Windows XP, open the Control Panel »Network and Internet Connections» »Network Connections.
3. If menngunakan Windows 7 or Vista, open Control Panel. In the Network and Internet icon, click View Status and Task Networks.
4.next will appear dialogNetworks city and Sharing Center. On the left side of this window, click on Change Adapter Settings
5.Klik Networkd right on your Card and select Properties.

6. In the Local Area Connection Properties window, select Internet Protocol (TCP / IP) in Windows XP or Internet Protocol Version 4 (TCP/IPv4) in Windows 7 and Vista. Then click the Properties button.

7.Pada Properties window that appears, select the option Use the followinf IP Address and fill in 192.168.0.1 in the IP Adrees, 255.255.255.0 in Subnetmask. The remaining inputs can you empty.
8. 8. Click OK to save the settings and click the OK button is also on the Local Area Connection Properties
Furthermore, for the second computer can be connected, then the Workgroup of these computers should be the same. For that, give the same workgroup name on the second computer. Do the following:
1. For users of Windows XP, open System Properties by right clicking the My Computer icon and select Properties. You can also press the keyboard combination Win + Break.
2. For users of Windows 7, the same way that is slightly open system properties in a way like on windows XP. In the window that appears click on Change Settings in the Computer name, domain, and workgroup settings.
3 In the System Properties window, either Windows XP, Vista or Windows 7, click the Change button.
4.Di next window provide a name for the computer 1 with the desired name. Suppose DK-1. And give the name of your workgroup.and the sample Computer World.
5. Click OK and click OK also on the System Properties window.
In order for the new changes you make affect the system, it is necessary to restart the process. For that retart your computer. Do the same steps as above to configure the network card and change the computer name and workgroup on both computers. However, the difference in computer 2, the IP address given is 192.168.0.2. Same Subnet 255.255.255.0. While the computer name must be different. Suppose the given name of the DK-2. However, the workgroup should be the same.
To determine whether the second computer is connected lakukanlanh ping from computer 1 to computer 2 or vice versa. How sebagia follows:
1. Open Command Prompt by pressing the Win + R keyboard
2. In CMD type the command "ping IP address". Ip Addrees filled with computer IP that you want to ping. If you do a ping from computer 1, then filled with an IP address IP 2. Vice versa. Example of ping command from computer 1 to computer 2:
ping 192.168.0.2
3. If the connection between two computers is successful then it will be like this:

Pinging 192.168.0.2 with 32 bytes of data:
Reply from 192.168.0.2: bytes=32 time<1ms TTL=128
Reply from 192.168.0.2: bytes=32 time<1ms TTL=128
Reply from 192.168.0.2: bytes=32 time<1ms TTL=128
Reply from 192.168.0.2: bytes=32 time<1ms TTL=128
Ping statistics for 192.168.0.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
4. Jika hasilnya seperti ini:
Pinging 192.168.0.2 with 32 bytes of data:
Request time out
Request time out
Request time out
Request time out
Ping statistics for 192.168.0.2:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss)

Means that the second computer is not connected. Try to check if the cable is connected properly or there might be a broken cable.
If everything is fine and the ping is good, it means you successfully mengubungkan these 2 computers. At Computer World next article will discuss how to share folders, printers and internet on the second computer. Similarly, a brief tutorial for
This tutorial is far from perfect and probably many mistakes that I made. If there is any among you who are more familiar about the network