How To Delete Data In Mysql Using PHP
How To Delete Data In Mysql Using PHP
Install PHP and PostgreSQL. Verify that PHP and PostgreSQL are both installed on your computer. They can be installed via package managers or downloaded from their official websites.
PHP code for a PostgreSQL connection
<?php
// Database configuration
$host = 'localhost';
$db = 'db';
$user = 'postgres';
$pass = 'password';
$port = '5432'; // Default port for PostgreSQL
// connection string
$conn_string = "host=$host port=$port dbname=$db user=$user password=$pass";
// Establish a connection to the PostgreSQL database
$conn = pg_connect($conn_string);
if (!$conn) {
echo "Error: Unable to connect database\n";
exit;
}
?>
1. In the part below, we can set our hostname. For local, you can use localhost. If you want to visit the other host, enter its hostname or server IP here.
<?php
$host = 'localhost';
?>
2. Here, we specify the name of our database.
<?php
$db = 'db';
?>
3. This is the DB user name code. Postgre is the default username for local users. However, you are free to design any kind of database user name.
<?php
$user = 'postgres';
?>
4. We can specify the database password here.
<?php
$pass = 'password';
?>
5. The Postgre post number can be defined here. 5432 is the port number by default.
<?php
$port = '5432';
?>
6. A new connection to the MySQL server is established via the pg_connect function.
<?php
// connection string
$conn_string = "host=$host port=$port dbname=$db user=$user password=$pass";
$conn = pg_connect($conn_string);
?>
NOTE: You must enable the pgsql extension in php.in in order to use Postgre Database with PHP.
How To Delete Data In Mysql Using PHP
How To Fetch Data In My Sql Using PHP