Database connection in php Reviewed by Momizat on . CRUD USING PHP & MYSQL SELECT INSERT UPDATE DELETE Connection With Mysql [php] <?php //error_reporting(0); //syntax mysql_connect("database_server_name CRUD USING PHP & MYSQL SELECT INSERT UPDATE DELETE Connection With Mysql [php] <?php //error_reporting(0); //syntax mysql_connect("database_server_name Rating: 0

Database connection in php

CRUD USING PHP & MYSQL

  • SELECT
  • INSERT
  • UPDATE
  • DELETE
Connection With Mysql
<?php 
//error_reporting(0);
//syntax
mysql_connect("database_server_name","database_user_name","database_password");
//Example of localhost server 
$con=mysql_connect("localhost","root","") or die("Invalid database server");
//select database
mysql_select_db("database_name",$con) or die("Invalid database");
//close server connection
mysql_close($con);

?>
Select operation With Mysql
  • mysql_fetch_array :- It’s return associative and numeric array format row from table.
  • mysql_fetch_assoc :- It’s return only associative array format row from table.
  • mysql_fetch_object :- It’s return object format row from table.
  • mysql_fetch_row :- It’s return only numeric array format row from table.
<?php
//error_reporting(0);
//syntax
mysql_connect("database_server_name","database_user_name","database_password");
//Example of localhost server 
$con=mysql_connect("localhost","root","") or die("Invalid database server");
//select database
mysql_select_db("database_name",$con) or die("Invalid database");
//close server connection

$sql="select * from tablename";
// execute query
$queexe=mysql_query($sql);
//count number of rows
$cnt=mysql_num_rows($queexe);
//fetch single row of record
$result=mysql_fetch_array($queexe);
//fetch multiple row of record using by while loop

while($result=mysql_fetch_array($queexe)){
echo "&lt;pre&gt;";print_r($result);
}

mysql_close($con);

?>
Insert operation With Mysql
<?php
//error_reporting(0);
//syntax
mysql_connect("database_server_name","database_user_name","database_password");
//Example of localhost server 
$con=mysql_connect("localhost","root","") or die("Invalid database server");
//select database
mysql_select_db("database_name",$con) or die("Invalid database");
//close server connection

$sql="insert into tablename (name) values ('manish')";
// execute query
$queexe=mysql_query($sql);


mysql_close($con);

?>
Update operation With Mysql
<?php
//error_reporting(0);
//syntax
mysql_connect("database_server_name","database_user_name","database_password");
//Example of localhost server 
$con=mysql_connect("localhost","root","") or die("Invalid database server");
//select database
mysql_select_db("database_name",$con) or die("Invalid database");
//close server connection

$sql="update tablename SET name='ramu' where id='1'";
// execute query
$queexe=mysql_query($sql);


mysql_close($con);

?>
Delete operation With Mysql
<?php
//error_reporting(0);
//syntax
mysql_connect("database_server_name","database_user_name","database_password");
//Example of localhost server 
$con=mysql_connect("localhost","root","") or die("Invalid database server");
//select database
mysql_select_db("database_name",$con) or die("Invalid database");
//close server connection

$sql="delete from tablename where id='1'";
// execute query
$queexe=mysql_query($sql);


mysql_close($con);

?>

Leave a Comment

© 2014 Powered By