Exemplo n.º 1
0
 public function checkUser($login, $passwd)
 {
     try {
         $connection = new DbConnection();
         $pdo = $connection->connect();
     } catch (ErrorException $e) {
         $еггог = 'crap3';
         include '../layouts/Error.html.php';
         exit;
     }
     try {
         $sql = 'SELECT id FROM users WHERE login = :login';
         $s = $pdo->prepare($sql);
         $s->bindValue(':login', $login);
         $s->execute();
     } catch (PDOException $e) {
         $еггог = 'crap4';
         include '../layouts/Error.html.php';
         exit;
     }
     if ($s->rowCount() > 0) {
         //            $_SESSION['user'] = $username;
         //        echo 2;
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 2
0
function login($login, $passwd)
{
    $connection = new DbConnection();
    $pdo = $connection->connect();
    try {
        $sql = 'SELECT id, name FROM users WHERE login = :login and passwd = :passwd';
        $s = $pdo->prepare($sql);
        $s->bindValue(':login', $login);
        $s->bindValue(':passwd', $passwd);
        $s->execute();
    } catch (PDOException $e) {
        $error = $e->getMessage();
        include APPLICATION_PATH . '/views/Error.html.php';
        exit;
    }
    $row = $s->fetch();
    return $row;
}
Exemplo n.º 3
0
 /**
  * Gets an instance of the the DbConnection
  * 
  * @param string $db_host
  * @param string $db_user
  * @param string $db_password
  * @param string $db_name
  * @return DbConnection
  * @todo Change to Use config from files.
  */
 public static function getInstance($connection = '')
 {
     if (empty($connection) || !isset(self::$_instances[$connection])) {
         $Config = Config::getInstance();
         if (empty($connection)) {
             $connection = $Config->system_enviroment;
         }
         $DbConfig = Config::getDbConfig($connection);
         $DbConnection = new DbConnection($DbConfig->db_host, $DbConfig->db_user, $DbConfig->db_password, $DbConfig->db_name);
         try {
             $DbConnection->connect();
         } catch (Exception $e) {
             loadErrorPage('nodb');
         }
         $DbConnection->executeQuery("SET CHARACTER SET 'utf8'");
         self::$_instances[$connection] = $DbConnection;
     }
     return self::$_instances[$connection];
 }
Exemplo n.º 4
0
function removePost($id)
{
    $connection = new DbConnection();
    $pdo = $connection->connect();
    try {
        $sql = "DELETE FROM posts WHERE id = :id";
        $s = $pdo->prepare($sql);
        $s->bindValue(':id', $id, PDO::PARAM_INT);
        $result = $s->execute();
    } catch (PDOException $e) {
        $error = $e->getMessage();
        include APPLICATION_PATH . '/views/Error.html.php';
        exit;
    }
    return $result;
}
 /**
  * Construct upgrade utility
  *
  * @param void
  * @return UpgradeUtility
  */
 function __construct()
 {
     $charset = defined('DB_CHARSET') && DB_CHARSET ? DB_CHARSET : null;
     $this->db =& DBConnection::instance();
     $this->db->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, true, $charset);
 }
Exemplo n.º 6
0
 /**
  * mixed XMLData(string $db, string $table, array $options = null)
  *
  * Returns the content of a table in XML format (Propel model more or less)
  *
  * @param string $db database name
  * @param string $table table name
  * @param array $options (optional) (from, to, start_table, end_table)
  * @return mixed false if error occurs, string if ok
  * @access public
  * @static
  * @see DUMP_CRLF
  */
 public static function XMLData($db, $table, $options = null)
 {
     $localConn = new DbConnection();
     if (!$localConn->connect()) {
         return false;
     }
     $localQuery = 'SHOW COLUMNS FROM ' . self::backQuote($table) . ' FROM ' . self::backQuote($db);
     if (!$localConn->exec($localQuery)) {
         return false;
     }
     for ($i = 0; $row = $localConn->fetchRow(MYSQL_ASSOC); $i++) {
         $fields[$i] = $row['Field'];
         $types[$i] = $row['Type'];
         $nulls[$i] = strtoupper($row['Null']) == 'YES' ? 'true' : 'false';
         $keys[$i] = $row['Key'];
         $defaults[$i] = $row['Default'];
         $extras[$i] = $row['Extra'];
     }
     $numFields = count($fields);
     // Defines the offsets to use
     $limitClause = isset($options['to']) && $options['to'] > 0 && (isset($options['from']) && $options['from'] >= 0) ? ' LIMIT ' . ($options['from'] > 0 ? $options['from'] . ', ' : '') . $options['to'] : '';
     $localQuery = 'SELECT * FROM ' . self::backQuote($db) . '.' . self::backQuote($table) . $limitClause;
     if (!$localConn->exec($localQuery)) {
         return false;
     }
     if ($localConn->numRows() == 0) {
         return '';
     }
     $buffer = '  <table name="' . $table . '">' . DUMP_CRLF;
     while ($record = $localConn->fetchRow(MYSQL_ASSOC)) {
         $buffer .= '    <row>' . DUMP_CRLF;
         for ($i = 0; $i < $numFields; $i++) {
             $element = ' name="' . $fields[$i] . '"' . ' type="' . $types[$i] . '"' . ($nulls[$i] ? ' null="' . $nulls[$i] . '"' : '') . ($keys[$i] ? ' key="' . $keys[$i] . '"' : '') . ($defaults[$i] ? ' default="' . $defaults[$i] . '"' : '') . ($extras[$i] ? ' extra="' . $extras[$i] . '"' : '');
             if (!is_null($record[$fields[$i]])) {
                 $buffer .= '      <column' . $element . '>' . htmlspecialchars($record[$fields[$i]]) . '</column>' . DUMP_CRLF;
             } else {
                 $buffer .= '      <column' . $element . ' />' . DUMP_CRLF;
             }
         }
         $buffer .= '    </row>' . DUMP_CRLF;
     }
     $localConn->close();
     $buffer .= '  </table>' . DUMP_CRLF;
     return $buffer;
 }
Exemplo n.º 7
0
        $mysql->query("INSERT INTO test_bug34810_table_1 VALUES (1),(2),(NULL)");
        $warning = $mysql->get_warnings();
        if (!$warning) {
            printf("[001] No warning!\n");
        }
        if ($warning->errno == 1048 || $warning->errno == 1253) {
            /* 1048 - Column 'a' cannot be null, 1263 - Data truncated; NULL supplied to NOT NULL column 'a' at row */
            if ("HY000" != $warning->sqlstate) {
                printf("[003] Wrong sql state code: %s\n", $warning->sqlstate);
            }
            if ("" == $warning->message) {
                printf("[004] Message string must not be empty\n");
            }
        } else {
            printf("[002] Empty error message!\n");
            var_dump($warning);
        }
    }
}
$db = new DbConnection();
$db->connect();
echo "Done\n";
error_reporting(0);
require_once "connect.inc";
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}
if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bug34810_table_1")) {
    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
mysqli_close($link);
Exemplo n.º 8
0
 */
/**
 * Controlling vars
 */
$tab = "admin";
$nav = "dump";
/**
 * Checking permissions
 */
require_once "../auth/login_check.php";
loginCheck(OPEN_PROFILE_ADMINISTRATOR, false);
// Not in DEMO to prevent users' malice
require_once "../lib/Dump.php";
@set_time_limit(OPEN_EXEC_TIME_LIMIT);
$auxConn = new DbConnection();
if (!$auxConn->connect()) {
    $auxConn->close();
    Error::connection($auxConn);
}
$localQuery = 'SHOW TABLE STATUS FROM ' . Dump::backQuote(OPEN_DATABASE);
if (!$auxConn->exec($localQuery)) {
    $auxConn->close();
    Error::connection($auxConn);
}
/**
 * Show page
 */
$title = _("Optimize Database");
require_once "../layout/header.php";
/**
 * Breadcrumb
Exemplo n.º 9
0
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
    } else {
        header('Content-Disposition: attachment; filename="' . $filename . '.' . $ext . '"');
        header('Expires: 0');
        header('Pragma: no-cache');
    }
}
// end download
/**
 * Builds the dump
 */
// Gets the number of tables if a dump of a database has been required
if (!isset($_POST['table_select']) || count($_POST['table_select']) != 1) {
    $auxConn = new DbConnection();
    $auxConn->connect();
    $result = $auxConn->listTables();
    $numTables = $result ? $auxConn->numRows() : 0;
    $single = false;
} else {
    $numTables = 1;
    $single = true;
}
// No table -> error message
if ($numTables == 0) {
    echo '# ' . _("No tables found in database.");
} else {
    // No csv or xml format -> add some comments at the top
    if ($_POST['what'] != 'csv' && $_POST['what'] != 'excel' && $_POST['what'] != 'xml') {
        switch ($_POST['what']) {
            case "data":