hello

Tuesday, September 23, 2014

3.2 Select

1) Connection
       
 
  //Connection variables -->START

$host = 'localhost';    /*domain name or host path*/
$user = 'root';         /*database username*/
$pass = 'your_db_pass'; /*database password*/ 
$database = 'db_users';    /*database name*/

//Connection variables-->END

       
 


2) Connection to Database

       
/*Create a connection to database*/
$connection = mysql_connect($host, $user, $pass) or die('Connection Failed');

/*Selecting the database based on suplied connection*/
$select_db = mysql_select_db($database, $connection) or die('Connection DB Failed');



3)The Query

       
/*Make a Query SELECT*/
$query = "select * from users_tbl";

/*Run the Query*/
$result = mysql_query($query) or die("Query Failed");

while($rows= mysql_fetch_array($result)){
 echo $rows['username'] .' - ' .$rows['password'].'
';
}



4) Full Code

       

//Connection variables -->START

$host = 'localhost';    /*domain name or host path*/
$user = 'root';         /*database username*/
$pass = 'your_db_pass'; /*database password*/ 
$database = 'db_users';    /*database name*/

//Connection variables-->END

/*Create a connection to database*/
$connection = mysql_connect($host, $user, $pass) or die('Connection Failed');

/*Selecting the database based on suplied connection*/
$select_db = mysql_select_db($database, $connection) or die('Connection DB Failed');

/*Make a Query SELECT*/
$query = "select * from users_tbl";

/*Run the Query*/
$result = mysql_query($query) or die("Query Failed");

while($rows= mysql_fetch_array($result)){
 echo $rows['username'] .' - ' .$rows['password'].'
';
}




No comments: