php Archives - PHPFOREVER https://phpforever.com/tag/php/ PHP LARAVEL CODEIGNITER DATABASE JAVASCRIPT Sat, 22 Jan 2022 01:42:19 +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 php Archives - PHPFOREVER https://phpforever.com/tag/php/ 32 32 PHP MySQL Select Data Using In Page https://phpforever.com/php/php-mysql-select-data-using-in-page/ https://phpforever.com/php/php-mysql-select-data-using-in-page/?noamp=mobile#respond Fri, 21 Jan 2022 05:31:43 +0000 https://phpforever.com/?p=2554 PHP MySQL Select Data Using In Page  – The following example selects the id, firstname and lastname columns from the MyGuests table and displays it on the page: Select Data From a MySQL Database The SELECT statement is used to select data from one or more tables: SELECT column_name(s) FROM table_name or we can use …

The post PHP MySQL Select Data Using In Page appeared first on PHPFOREVER.

]]>
PHP MySQL Select Data Using In Page  – The following example selects the id, firstname and lastname columns from the MyGuests table and displays it on the page:

Select Data From a MySQL Database

The SELECT statement is used to select data from one or more tables:

SELECT column_name(s) FROM table_name

or we can use the * character to select ALL columns from a table
SELECT * FROM table_name

Example (MySQLi Object-oriented)

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
  while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>

 

php-code-to-retrieve-data-from-mysql-database-and-display-in-html-table

Code lines to explain from the example above:

First, we set up an SQL query that selects the id, firstname and lastname columns from the MyGuests table. The next line of code runs the query and puts the resulting data into a variable called $result.

The post PHP MySQL Select Data Using In Page appeared first on PHPFOREVER.

]]>
https://phpforever.com/php/php-mysql-select-data-using-in-page/feed/ 0
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.

]]>