PDO connect
<?php
$db = new PDO('mysql:host=myhost;dbname=mydb', 'login', 'password');
PDO connect
<?php
$db = new PDO('mysql:host=myhost;dbname=mydb', 'login', 'password');
php mysql connect pdo
$host = 'localhost'; // URL to the server
$user = 'root'; // Username (xampp = root)
$pw = ''; // Password (xampp = )
$dbname = 'database'; // The name of your database
$dsn = "mysql:host=$host;dbname=$dbname";
$options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']; // If you want to use utf-8 use this line
$db = new PDO($dsn, $user, $pw, $options); // Database Object
$db -> setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); // Use this if you want an associate array
// $db -> setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); Use this if you want an indexed array
$qry = 'select * from table;'; // Your query
$result = $db -> query($qry); // execute query
while ($row = $result -> fetch()) {
$id = $row[/*column-name*/];
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us