public function __construct()
{
// Set DSN
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
// Set options
$options = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
// Create a new PDO instanace
try{
$this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
}
// Catch any errors
catch(PDOException $e){
$this->error = $e->getMessage();
}
} // <-- Уберите эту скобку!
}
<?php if ( ! isset($_POST['item_a'], $_POST['item_b'])): ?>
<!-- Begin form -->
<form action="" method="POST" role="form">
<!-- Item a -->
<div class="from-gorup">
<label for="item_a">Enter item_a</label>
<input type="text" name="item_a" class="form-control" id="item_a">
</div>
<!-- Item b -->
<div class="from-gorup">
<label for="item_b">Enter item_b</label>
<input type="text" name="item_b" class="form-control" id="item_b">
</div>
<!-- Submit button -->
<button type="submit" class="btn btn-primary">Submit!</button>
</form><!-- End form -->
<?php else: ?>
<p>item_a + item_b = <?php echo $_POST['item_a'] + $_POST['item_b']; ?></p>
<?php endif; ?>
$host = "localhost";
$user = "root";
$pass = "";
$db_name = "base";
$db = mysql_connect($host,$user,$pass);
mysql_select_db($db_name,$db);
$id = 23; // для примера
$res = mysql_query(" SELECT id FROM table_name");
while ($item = mysql_fetch_array($res))
{
if ($item['id'] == $id)
{
$query = "INSERT INTO table_name (id) VALUES('{$id}')";
mysql_query($insert_sql);
echo $i . ", ";
}
}
echo "<br>" . mysql_num_rows($res);