<?php$servername="localhost";
$username="username";
$password="password";
try {
$conn=newPDO("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 April-10-2020
1
connect php to mysql pdo
<?php$pdo=newPDO('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 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=newPDO($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 querywhile ($row=$result->fetch()) {
$id=$row[/*column-name*/];
}
Posted by: Guest
on March-03-2021
0
mssql pdo
Hi All, I'wrote a class to connect to MSSQL/Azure databases with Transaction support.
Hope this can help anyone!<?php/**
* @author Johan Kasselman <johankasselman@live.com>
* @since 2015-09-28 V1
*
*/classpdo_dblib_mssql{
private$db;
private$cTransID;
private$childTrans=array();
publicfunction__construct($hostname, $port, $dbname, $username, $pwd){
$this->hostname =$hostname;
$this->port =$port;
$this->dbname =$dbname;
$this->username =$username;
$this->pwd =$pwd;
$this->connect();
}
publicfunctionbeginTransaction(){
$cAlphanum="AaBbCc0Dd1EeF2fG3gH4hI5iJ6jK7kLlM8mN9nOoPpQqRrSsTtUuVvWwXxYyZz";
$this->cTransID ="T".substr(str_shuffle($cAlphanum), 0, 7);
array_unshift($this->childTrans, $this->cTransID);
$stmt=$this->db->prepare("BEGIN TRAN [$this->cTransID];");
return$stmt->execute();
}
publicfunctionrollBack(){
while(count($this->childTrans) >0){
$cTmp=array_shift($this->childTrans);
$stmt=$this->db->prepare("ROLLBACK TRAN [$cTmp];");
$stmt->execute();
}
return$stmt;
}
publicfunctioncommit(){
while(count($this->childTrans) >0){
$cTmp=array_shift($this->childTrans);
$stmt=$this->db->prepare("COMMIT TRAN [$cTmp];");
$stmt->execute();
}
return$stmt;
}
publicfunctionclose(){
$this->db =null;
}
publicfunctionconnect(){
try {
$this->db =newPDO ("dblib:host=$this->hostname:$this->port;dbname=$this->dbname", "$this->username", "$this->pwd");
} catch (PDOException$e) {
$this->logsys .="Failed to get DB handle: ".$e->getMessage() ."\n";
}
}
}
?>
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
Check Your Email and Click on the link sent to your email