Answers for "how to use pdo in php"

PHP
2

how to connect pdo php database

<?php
$servername = "localhost";
$username = "username";
$password = "password";

try {
  $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
  // set the PDO error mode to exception
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  echo "Connected successfully";
} catch(PDOException $e) {
  echo "Connection failed: " . $e->getMessage();
}
?>
Posted by: Guest on May-14-2020
1

connect php to mysql pdo

<?php 
  
	$pdo = new PDO('mysql:host=localhost;
  				dbname=the_name_of_your_databe,
  				'username', 
                'password'');
# by default your username is root 
# if you don't have a password don't fill in it

#(optional) : 
	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

?>
Posted by: Guest on April-25-2020
0

php pdo code examples

<?php

$dsn = "mysql:host=localhost;dbname=mydb";
$user = "user12";
$passwd = "12user";

$pdo = new PDO($dsn, $user, $passwd);

$stm = $pdo->query("SELECT * FROM countries");

$rows = $stm->fetchAll(PDO::FETCH_NUM);

foreach($rows as $row) {

    printf("$row[0] $row[1] $row[2]\n");
}
Posted by: Guest on July-09-2021

Browse Popular Code Answers by Language