Search
 
SCRIPT & CODE EXAMPLE
 

PHP

pdo fetch


<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();

/* Exercise PDOStatement::fetch styles */
print("PDO::FETCH_ASSOC: ");
print("Return next row as an array indexed by column name
");
$result = $sth->fetch(PDO::FETCH_ASSOC);
print_r($result);
print("
");

print("PDO::FETCH_BOTH: ");
print("Return next row as an array indexed by both column name and number
");
$result = $sth->fetch(PDO::FETCH_BOTH);
print_r($result);
print("
");

print("PDO::FETCH_LAZY: ");
print("Return next row as an anonymous object with column names as properties
");
$result = $sth->fetch(PDO::FETCH_LAZY);
print_r($result);
print("
");

print("PDO::FETCH_OBJ: ");
print("Return next row as an anonymous object with column names as properties
");
$result = $sth->fetch(PDO::FETCH_OBJ);
print $result->name;
print("
");
?>

Comment

Fetch Data From Database With PDO

$host = 'localhost'; // URL to the server
$username = 'root'; // Username (xampp = root)
$password = ''; // Password (xampp = )
$dbname = 'apifile';
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$sql = "SELECT * FROM `prop` WHERE propkey='localhost_100100'";

$q = $pdo->query($sql);

$q->setFetchMode(PDO::FETCH_ASSOC);
$r = $q->fetch();
var_dump($r['propvalue']);
Comment

php pdo fetch from db

$pdo = new PDO('mysql:host=$host; dbname=$database;', $user, $pass);
$stmt = $pdo->prepare('SELECT * FROM auction WHERE name = :name');
$stmt->bindParam(':name', $_GET['searchdivebay']);
$stmt->execute(array(':name' => $name);
Comment

PREVIOUS NEXT
Code Example
Php :: just page name in url 
Php :: Route::auth(); giving error in laravel 7 
Php :: error php 
Php :: yii framework 
Php :: random String Function PHP 
Php :: Select specefied columns from all data in laravel 
Php :: php send values in $_SESSION to other page 
Php :: php nested array 
Php :: $this 
Php :: laravel http response with cookie 
Php :: learn php basic 
Php :: How to protect your website from DDos Attack? 
Php :: progress bar calculate percentage php 
Php :: active class php 
Java :: vm options javafx 
Java :: convert string to localdatetime 
Java :: spigot get player from uuid 
Java :: what are the hibernate dependencies 
Java :: how to loop through code 3 times java 
Java :: java age from date 
Java :: java setinterval equivalent 
Java :: How to solve the towers of Hanoi Java? 
Java :: datentypen java 
Java :: convert string to int java 
Java :: how to put icons inside of an edittext android 
Java :: spring load config value in variable 
Java :: how to convert object to list in java 
Java :: java string join arraylist 
Java :: random processing 
Java :: getcurrencyinstance java india 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =