dbwrappersample.php

Gesponsorde koppelingen

PHP script bestanden

  1. pdowrapper.php
  2. dbwrappersample.php

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
 
  try{
    $db = new MySQL('user', 'pass', array('host' => 'localhost', 'port' => 3306, 'dbname' => 'mydb'));
    //$db = new MySQL('user', 'pass', 'host=localhost;port=3306;dbname=mydb;', array(PDO::OPTION => 'value'));
    
    $db->exec('SET GLOBAL general_log_file = "/var/log/mysql.log";');
    $db->exec("SET GLOBAL general_log = 'ON';");
    
    echo $db->tableExists('settings') ? ' yes' : ' no';
    
    // single inline code. execute exepects any number of variables, arrays needs to be multi indexed with param names.
    $db->prepare("select username, password FROM users WHERE username=?")->execute((string)$_POST['password'])->rowCount() == 1;
    $db->prepare("select username, password FROM users WHERE username=:pass")->execute(array('pass' => (string) $_POST['password'])->rowCount() == 1;
    
    // or normal usage, pass nothing in execute and use the sth variable as you normally would.
    $db->prepare("select username, password FROM users WHERE username=:pass");
    $db->sth->bindValue(':pass', $_POST['password']);
    echo $db->execute()->rowCount();
    
    $db->prepare("select * from settings")->execute();
    
    while($row = $db->fetchAssoc()){ //fetchBoth, fetchObj, fetchNum, fetchLazy.
      print_r($row);
    }

    
    $db->selectDatabase("otherdb");
    
    // kill
    $db = null;
  }
catch(PDOException $e){
    echo $e->getMessage();
  }
catch(DatabaseException $e){
    echo $e->getMessage();
  }
catch(Exception $e){
    die($e->getMessage());
  }

  
?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.