Main Menu

friends

Latest articles

display bandwidth usage on an interface by host with iftop
11/05/2010 | mad mad mod

iftop  listens to network traffic on an interface and displays the result in a nice "top-like" style. iftop does for network usage what top does for CPU usage. Homepage: http://www.ex-parrot.com [ ... ]


How to get the current network bandwidth usage on Linux
07/04/2010 | mad mad mod

There are many ways how to get the current bandwidth usage on Linux. This is a very simple shell script that lists the network statistic every second: #!/bin/bash
if [ -z "$1" ]; then
       [ ... ]


Other Articles
Facebook MySpace Twitter Digg Delicious Stumbleupon Google Bookmarks 

Designed by:
SiteGround web hosting Joomla Templates
very simple mysql connection from php E-mail
programming

This article describes how to connect to a mysql database from a php script. It is realy the most simple way of using mysql databases in php, no fancy wrapper classes, no functions and NO security! We will care about that later...

 

 

Step 1: Connect to the mysql server

 

The command to do that is "mysql_connect" and the return value is either a connection-id or FALSE.

 

example:

 

<?PHP

$connect=mysql_connect("localhost", "dbadmin", "password");
if (!$connect) {
die('connection not possible: ' . mysql_error());
}

?>

 

In this example the mysql server and the webserver are running on the same server (localhost).

 

 

Step 2: select a database


The command to do that is "mysql_select_db" and the return value is either TRUE or FALSE.

 

example:

 

<?PHP

$connect=mysql_connect("localhost", "dbadmin", "password");

if (!$connect) {
die('connection not possible: ' . mysql_error());
}

$db=mysql_select_db("mydatabase",$connect);

if (!$db) {
die('could not select database: ' . mysql_error());
}


?>

 

 

Step 3: make a query

 

The command to make a query is "mysql_query" and the return value is either TRUE, FALSE or a resource id.

 

example:

 

<?PHP



(...)



$db=mysql_select_db("mydatabase",$connect);

if (!$db) {
die('could not select database: ' . mysql_error());
}

$result = mysql_query('SELECT * FROM mytable');
if (!$result) {
die('query failed: ' . mysql_error());
}
?>

 

Ok, but where is the result now? $result only contains a resource id and the command to read the real result is mysql_fetch_array(). mysql_fetch_array returns an array with the result from our query.

 

 

<?PHP

 

(...)


while ($row = mysql_fetch_array($result)) {
print ("row 0: " . $row[0]);
print (" row 1: " . $row[1]);
print ("\n");
}
?>

 

 

All together

 

 

<?PHP

$connect=mysql_connect("localhost", "dbadmin", "password");
if (!$connect) {
die('connection not possible: ' . mysql_error());
}


$db=mysql_select_db("mydatabase",$connect);

if (!$db) {
die('could not select database: ' . mysql_error());
}



$result = mysql_query('SELECT * FROM mytable');
if (!$result) {
die('query failed: ' . mysql_error());
}



while ($row = mysql_fetch_array($result)) {
print ("row 0: " . $row[0]);
print (" row 1: " . $row[1]);
print "\n";
}

?>

 

 

Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

 
mad mad mod, Powered by Joomla! and designed by SiteGround web hosting