insert Archives - PHPFOREVER https://phpforever.com/tag/insert/ PHP LARAVEL CODEIGNITER DATABASE JAVASCRIPT Wed, 16 Oct 2019 17:12:24 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://phpforever.com/wp-content/uploads/2020/06/cropped-PHP4EVER1-1-32x32.png insert Archives - PHPFOREVER https://phpforever.com/tag/insert/ 32 32 How To Insert Data Into Database Using PHP And PostgreSQL https://phpforever.com/php/how-to-insert-data-into-database-using-php-and-postgresql/ Sat, 18 May 2019 06:16:04 +0000 http://phpforever.com/?p=423 If you want to insert data into postgresql using PHP then you are at right place.In this post we will learn how to connect postgresql with php and insert data into database. Step 1 : Create Table. CREATE TABLE EMP (ID SERIAL PRIMARY KEY, NAME TEXT NOT NULL, MOBNO INT NOT NULL, EMAIL TEXT NOT …

The post How To Insert Data Into Database Using PHP And PostgreSQL appeared first on PHPFOREVER.

]]>
If you want to insert data into postgresql using PHP then you are at right place.In this post we will learn how to connect postgresql with php and insert data into database.

Step 1 :  Create Table.
CREATE TABLE EMP
      (ID       SERIAL PRIMARY KEY,
      NAME      TEXT    NOT NULL,
      MOBNO      INT     NOT NULL,
      EMAIL   TEXT     NOT NULL
      )




Step 2 :Create Database Connection
.
<?php 
 $host = "localhost";
$port = "5432";
$dbname = "demo";
$user = "postgres";
$password = "*****";

$connection_string = "host={$host} port={$port} dbname={$dbname} user={$user} password={$password} ;
$conn = pg_connect($connection_string);
if($conn){
    echo "Connected to ". pg_host($dbconn); 
}else{
    echo "Error in connecting to database.";
}
?>

Step 3:Create Insert Code Connection
.

<?php 
$sql = "insert into emp (NAME, MOBNO, Email)  values('postgre', 68687, 'test@gmail.com')";
$result = pg_query($conn, $sql);
if(!$result){
  echo pg_last_error($dbconn);
} else {
  echo "Inserted successfully";
}
?>

The post How To Insert Data Into Database Using PHP And PostgreSQL appeared first on PHPFOREVER.

]]>