本文整理匯總了PHP中PDO::bindParam方法的典型用法代碼示例。如果您正苦於以下問題:PHP PDO::bindParam方法的具體用法?PHP PDO::bindParam怎麽用?PHP PDO::bindParam使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PDO
的用法示例。
在下文中一共展示了PDO::bindParam方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: dataConnectivity
public function dataConnectivity()
{
try {
$dbh = new PDO('mysql:host=localhost;dbname=exads', 'root', 'root', array(PDO::ATTR_PERSISTENT => false));
$stmt = $dbh->prepare("SELECT name,age,job_title FROM exads_test");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($rows);
unset($stmt);
$name = "Sara";
$age = 32;
$title = "developer";
$stmt = $dbh->prepare("INSERT INTO exads_test (name,age,job_title) VALUES (:name,:age,:job_title);");
$dbh->bindParam(":name", $name, PDO::PARAM_STR);
$dbh->bindParam(":age", $age, PDO::PARAM_INT);
$dbh->bindParam(":job_title", $title, PDO::PARAM_STR);
$stmt->execute();
unset($stmt);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die;
}
}
示例2: json_encode
<?php
$oDb = new PDO("sqlite:" . __DIR__ . "/cds.sqlite");
//$sQuery = "';DROP DATABASE testme;#'";
$sQuery = "pop";
if (isset($_GET['Genre'])) {
$sQuery = $_GET['Genre'];
}
$oDb->prepare("SELECT * FROM `cds` WHERE genre = :genre");
$oDb->bindParam("genre", $sQuery);
$oDb->execute();
$aResults = $oDb->fetchAll(PDO::FETCH_OBJ);
echo json_encode($aResults);