Академический Документы
Профессиональный Документы
Культура Документы
It is always a good practice to write the connection string for the database in a separate file
and call it on each page where the the database is required. To know how to call the file
see PHP Tips (Server Side Includes).
So we first create a file where we assign the values for your server, the database you want
to connect,the user name and the password to variables. Let us save this file as conn.php
<?php
$strServer="66.9.65.200"; //
Server
$strDatabase="database
IP
name"; //
$strUser="root"; //
Address
Or
Database
User
$strPwd="pwd";//
Name
Name
ID
Password
?>
Now we can call
Server
IP
Address
Database
User
Or
Name
Name
ID
Password
Create a connection.
2.
Select a database.
3.
Execute Queries.
4.
5.
[Close the connection]. Not necessary, because the connection get closed, when the web page
is sent from the server.
The last line is just inserting an entry. By the way, please remember the username, password and
the server(localhost usually) of the database that you have created. (For an example I've use root,
with no password onlocalhost).
Finally, lets do some coding.
/*The thing that you should know under which element the 'Name' field will be
located. That's not hard since you know about the table structure. So zero
will be ID, one is Name, Two is DOB and likewise. This is not terribly hard,
but if you want to use the field name instead, you could either use
while($myresult=mysql_fetch_array($result, MYSQL_ASSOC)){
or
while($myresult=mysql_fetch_assoc($result)){
in both case you can use like this,
echo $myresult['Name'];
*/
}
}
/*Closing the connection is not necessary as I've explained earlier, anyway
I'll include it. */
mysql_close($db);
Note:
That's about it. For INSERT, UPDATE,
DELETE or REPLACE use mysql_affected_rows([resource identifier])to check whether
how many rows are affected and for SELECT, DESCRIBE,
SHOW or EXPLAIN usemysql_num_rows([resource identifier]).
Summary.
1.
Create a connection.
2.
Select a database.
3.
Execute Queries.
4.
5.
[Close the connection]. Not needed, coz' anyway the connection get closed when the web
page is sent from the server.
Architecture:
1.
Search by Name: Use a file called search.php, sends details to address.php i.e
name=xx&type=display
2.
3.
4.
5.
6.
Have a Simple Navigator to move from one record to another: Have a different file and
include it when ever needed.