Reputation: 749
Hi i get a value with post methos and i want to check it with function func_check_seven_userid()
when i use :
$stmt = $this->conn->prepare("SELECT * FROM content where content_id= ".$this->seven);
$stmt->execute();
it work.
but when i use :
$stmt = $this->conn->prepare("SELECT * FROM content WHERE content_id = :id");
$stmt->execute(array(":id" => $this->seven));
it is not work!!!
my complet code is :
<?php
class insert_content {
private $conn;
private $seven;
private $row_id;
//**********************************************************************
function connect() {
include 'db_connection.php';
try {
$this->conn = new PDO("mysql:host=$servername;dbname=$db_name", $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
echo "Connection failed: " . $e->getMessage();
}
}
//************************************************************************
private function func_check_seven_userid() {
$stmt = $this->conn->prepare("SELECT * FROM content WHERE content_id = :id");
$stmt->execute(array(":id" => $this->seven));
$row = $stmt->fetch();
$this->row_id = $row[0];
if ($this->row_id) {
echo 'yes';
}
else {
echo 'no';
}
}
//****************************************************************
function __construct($parms) {
$this->connect();
$this->seven = $parms['seven'];
$this->func_check_seven_userid();
}
function __destruct() {
$this->conn = null;
}
}
if (isset($_POST['seven'])) {
$parms = array('seven' => ($_POST['seven']));
$class = new insert_content($parms);
}
?>
thanks for help
Upvotes: 0
Views: 213
Reputation: 137
I found this:
<?php
/* Execute a prepared statement by passing an array of values */
$sql = 'SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour';
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->execute(array(':calories' => 150, ':colour' => 'red'));
$red = $sth->fetchAll();
$sth->execute(array(':calories' => 175, ':colour' => 'yellow'));
$yellow = $sth->fetchAll();
?>
on http://php.net/manual/en/pdo.prepare.php
Here the statement is prepared with PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY
Maybe it does the difference. Hope it helps
Upvotes: 1