Search
 
SCRIPT & CODE EXAMPLE
 

PHP

select in php mysql

<?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();
?>
  
  //aamirAlshawa
Comment

query sql in php

$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();
Comment

select sql in php

<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");

if ($mysqli -> connect_errno) {
  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  exit();
}

$sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";
$result = $mysqli -> query($sql);

// Associative array
$row = $result -> fetch_assoc();
printf ("%s (%s)
", $row["Lastname"], $row["Age"]);

// Free result set
$result -> free_result();

$mysqli -> close();
?>
//eng.aamirAlshawa
Comment

select query in php

// objected oriented method
<?php
	$con=new mysqli("localhost","root","","dbname");
	$sql="select * from tbl";
	$res=$con->query($sql);
	
	$while($fetch=$res->fetch_object(){
      echo $fetch->uid;
      echo $fetch->uname;
      echo $fetch->unumber;
    }
  
?>
Comment

select query in php

$mquery = mysql_query("SELECT * FROM 
users where `userid
` = 1");
$result = mysql_fetch_arrray($mquery);
echo $result['name'];
Comment

PREVIOUS NEXT
Code Example
Php :: separate date from datetime php 
Php :: how to replace double quotes in a string in php 
Php :: php sql get single value 
Php :: if object or array in php 
Php :: php days remaining 
Php :: minus 1 year php 
Php :: php mongodb version cmd 
Php :: laravel blade upper case 
Php :: laravel eloquent to array key value 
Php :: if condition inside echo in php 
Php :: laravel http retry 
Php :: column of csv to array php 
Php :: How to format a json response in php 
Php :: How to call soap api in php using curl method 
Php :: delete all cookies in php 
Php :: php split array in half 
Php :: add 1 day php datetime 
Php :: Laravel randomise data from database 
Php :: php random integer 
Php :: wordpress programmatically logout 
Php :: laravel make view 
Php :: php pdo check if update query successful 
Php :: replace php 
Php :: getMessage in php 
Php :: laravel model query limit 
Php :: add days to date in php 
Php :: php previous page 
Php :: redirect woocommerce thank you 
Php :: php append element to array 
Php :: Modes for File Read PHP 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =