note 117321 deleted from pdo.query by cmb
| From: | cmb@php.net | Date: | Sun, 05 Jan 2020 08:57:54 +0000 |
| Subject: | note 117321 deleted from pdo.query by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213793@lists.php.net to get a copy of this message | ||
Note Submitter: tgrl5000
----
Connecting
==============================
<?php
try{
$db = new
PDO("dbtype:host=yourhost;dbname=yourdbname;charset=utf8","username","password");
/*Other Codes*/
}catch(PDOException $e ){
echo "Error: ".$e;
}
?>
Excute query with secure data
==============================
<?php
try{
$db = new
PDO("dbtype:host=yourhost;dbname=yourdbname;charset=utf8","username","password");
$mysecuredata=14;
$db->query("Select * from table where id=".$mysecuredata);
}catch(PDOException $e ){
echo "Error: ".$e;
}
?>
Excute query with insecure data
==============================
<?php
try{
$db = new
PDO("dbtype:host=yourhost;dbname=yourdbname;charset=utf8","username","password");
$myinsecuredata=$_GET["id"];
$query=$db->prepare("Select * from table where id=?");
$query->excute(array($myinsecuredata));
}catch(PDOException $e ){
echo "Error: ".$e;
}
?>
Getting Data in database
==============================
<?php
try{
$db = new
PDO("dbtype:host=yourhost;dbname=yourdbname;charset=utf8","username","password");
$myinsecuredata=$_GET["table"];
$query=$db->prepare("Select * from ?");
$query->excute(array($myinsecuredata));
while($row=$query->fetch(PDO::FETCH_OBJ)) {
/*its getting data in line.And its an object*/
echo $row->yourcolumnname;
}
}catch(PDOException $e ){
echo "Error: ".$e;
}
?>
Reference
==============================
http://gencbilgin.net/pdo-kullanimi-php-de-veritabani-islemleri.html