本文整理汇总了PHP中Db::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::prepare方法的具体用法?PHP Db::prepare怎么用?PHP Db::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::prepare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ejecutar
/**
* Función para ejecutar consultar de tipo INSERT, UPDATE, DELETE
* @param array $parametros
* @param string $sql
*/
protected function ejecutar($parametros, $sql = null)
{
if ($sql == null) {
$sql = $this->sql;
}
$sentencia = $this->db->prepare($sql);
if (!$sentencia->execute($parametros)) {
self::enviarError($this->db->errorInfo());
}
}
示例2: evolve
public function evolve($buildingId)
{
$buildingCost = $this->db->prepare("SELECT\n lvl.food,\n lvl.gold\n FROM\n userbuildings ub\n INNER JOIN\n buildinglvldefs lvl ON ub.level_id + 1 = lvl.id\n WHERE\n ub.id = ?");
$buildingCost->execute([$buildingId]);
$buildingCost = $buildingCost->fetch();
if ($this->user->getGold() < $buildingCost['gold'] || $this->user->getFood() < $buildingCost['food']) {
throw new \Exception("Not enough resources.");
}
if (!$this->lvlCompare($buildingId)) {
throw new \Exception('Max level reached.');
}
$this->user->setGold($this->user->getGold() - $buildingCost['gold']);
$this->user->setFood($this->user->getFood() - $buildingCost['food']);
$update = $this->db->prepare("UPDATE\n userbuildings\n SET\n level_id = level_id + 1\n WHERE\n user_id = ?\n AND\n id = ?");
$update->execute([$_SESSION["user_id"], $buildingId]);
}
示例3: getMe
/**
* @todo: store user token from request globally in config object, use username / token to find user and so on
* @todo: logic must be in Usermodel, move later
* @returns models\User
*/
public function getMe()
{
$oDb = Db::getInstance();
$oUser = new models\User();
$aUser = $oDb->getArray(Db::prepare("SELECT * FROM %s;", [$oUser->getTableName()]));
return array_shift($aUser);
}
示例4: tambahKategori
function tambahKategori($nmkategori)
{
$db = new Db();
$stmt = $db->prepare("INSERT INTO kategori (nmkategori) VALUES (?)");
$stmt->bindParam(1, $nmkategori);
$stmt->execute();
echo "Data Kategori berhasil di simpan";
}
示例5: get_static_modifiers
public static function get_static_modifiers($user_id)
{
$sql = "SELECT * FROM modifiers WHERE user_id = :user_id";
$req = Db::prepare($sql);
$req->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$req->execute();
return $res = $req->fetch(PDO::FETCH_ASSOC);
}
示例6: tambahKategori
function tambahKategori($cat_name)
{
$db = new Db();
$stmt = $db->prepare("INSERT INTO part_cat (cat_name) VALUES (?)");
$stmt->bindParam(1, $cat_name);
$stmt->execute();
echo "Data Kategori berhasil di simpan";
}
示例7: tampilLaptop
function tampilLaptop($brand, $model, $thn_keluar)
{
$db = new Db();
$stmt = $db->prepare("SELECT * FROM laptop");
$stmt->bindParam(1, $brand);
$stmt->bindParam(2, $model);
$stmt->bindParam(3, $thn_keluar);
$stmt->execute();
}
示例8: tampilLaptop
function tampilLaptop($brand, $model, $release)
{
$db = new Db();
$stmt = $db->prepare("SELECT * FROM laptops");
$stmt->bindParam(1, $brand);
$stmt->bindParam(2, $model);
$stmt->bindParam(3, $release);
$stmt->execute();
echo "";
}
示例9: tambahProduk
function tambahProduk($brand, $model, $release_year)
{
$db = new Db();
$stmt = $db->prepare("INSERT INTO komputer (brand, model, release_year) VALUES (?, ?, ?)");
$stmt->bindParam(1, $brand);
$stmt->bindParam(2, $model);
$stmt->bindParam(3, $release_year);
$stmt->execute();
echo "Sukses";
}
示例10: tambahLaptop
function tambahLaptop($brand, $model, $thn_keluar)
{
$db = new Db();
$stmt = $db->prepare("INSERT INTO laptop (brand, model, thn_keluar) VALUES (?, ?, ?)");
$stmt->bindParam(1, $brand);
$stmt->bindParam(2, $model);
$stmt->bindParam(3, $thn_keluar);
$stmt->execute();
echo "Data Laptop berhasi di simpan";
}
示例11: tambahSukuCadang
function tambahSukuCadang($id_laptop, $id_cat, $part_number, $description)
{
$db = new Db();
$stmt = $db->prepare("INSERT INTO sukucadang (id_laptop,id_cat,part_number,description) VALUES (?, ?, ?, ?)");
$stmt->bindParam(1, $id_laptop);
$stmt->bindParam(2, $id_cat);
$stmt->bindParam(3, $part_number);
$stmt->bindParam(4, $description);
$stmt->execute();
echo "Data Suku Cadang berhasil di simpan";
}
示例12: tambahSukuCadang
function tambahSukuCadang($laptop_id, $kategori_id, $no_sukucadang, $keterangan)
{
$db = new Db();
$stmt = $db->prepare("INSERT INTO sukucadang (laptop_id,kategori_id,no_sukucadang,keterangan) VALUES (?, ?, ?, ?)");
$stmt->bindParam(1, $laptop_id);
$stmt->bindParam(2, $kategori_id);
$stmt->bindParam(3, $no_sukucadang);
$stmt->bindParam(4, $keterangan);
$stmt->execute();
echo "Data Suku Cadang berhasil di simpan";
}
示例13: add
public function add()
{
$fields = $this->format_request();
$sql = "INSERT troops SET {$fields['sql_params']}\n ON DUPLICATE KEY UPDATE quantity = quantity + :quantity";
$req = Db::prepare($sql);
foreach ($fields['bind_params'] as $field) {
$req->bindParam($field['name'], $field['value'], $field['type']);
}
if ($req->execute()) {
return Db::getLastInsertId();
}
return false;
}
示例14: testInsertWithPreparedStatement
public function testInsertWithPreparedStatement()
{
$this->checkIfFooIsEmpty();
$o_stmt = $this->db->prepare("INSERT INTO foo (id, comment) VALUES (?, ?)");
$o_stmt->execute(array(1, 'bar'));
$qr_select = $this->db->query("SELECT * FROM foo");
$this->assertInternalType('object', $qr_select);
$this->assertTrue($qr_select->nextRow());
$this->assertEquals(1, $qr_select->get('id'));
$this->assertEquals('bar', $qr_select->get('comment'));
$this->db->query("DELETE FROM foo");
$this->checkIfFooIsEmpty();
}
示例15: destroy
public function destroy($id)
{
//remove session record from the database and return result
$res = $this->db->prepare("DELETE FROM {$this->table} WHERE id = :session_id");
$res->execute(array(':session_id' => $id, ':data' => $data));
if ($res->rowCount()) {
return true;
}
}