Example #1
0
 /**
  * Vy`polnenie zaprosa i vozvrashchenie deskriptora na rezul`tat
  *
  * Dlia khranimy`kh protcedur
  * - Zamer vremeni vy`polneniia zaprosa
  * - V sluchae oshibki vozvrashchaet false
  * - Zapis` zaprosa i vremeni ego vy`polneniia v fai`l-loge
  *
  * @param string $sql zapros k BD
  * @return bool|mysqli_result
  * @throws Exception
  */
 protected static function Query_Real($sql)
 {
     Zero_Logs::Info('#{SQL} ' . $sql);
     $res = self::$DB->real_query($sql);
     if (!$res) {
         Zero_Logs::Error('#{SQL ERROR} ' . self::$DB->error);
         Zero_Logs::Error('#{SQL} ' . $sql);
         throw new Exception(self::$DB->error, 500);
     }
     return $res;
 }
Example #2
0
 public function execute($sql, array $parameters = null)
 {
     $this->initConnection();
     if ($parameters) {
         $sql = $this->escapeSql($sql, $parameters);
     }
     $this->log($sql);
     if (!$this->mysql->real_query($sql)) {
         $this->checkDbError($sql);
     }
 }
Example #3
0
 public function insert($sql)
 {
     $this->errorCode = 0;
     $this->lastSql = $sql;
     if (!$this->MySqli->real_query($sql)) {
         $this->error('insert');
     }
     $this->numRows = $this->MySqli->affected_rows;
     return $this;
     //For chaining and PONIES!!!
 }
Example #4
0
 /**
  * @param string $query
  * @return bool|null
  */
 public function real_query($query)
 {
     $result = parent::real_query($query);
     if ($this->errno) {
         $error = $this->error;
         $this->rollback();
         $this->ThrowQueryError($query, $error);
         return null;
     } else {
         return $result;
     }
 }
Example #5
0
 /**
 	Initialises a mysql prepared statement.
 
 	@param	$oDb	The mysql link resource.
 	@param	$sQuery	The query.
 */
 public function __construct(weeDatabase $oDb, mysqli $oMySQLi, $sQuery)
 {
     preg_match_all('/:([\\w_]+)/', $sQuery, $aMatches, PREG_OFFSET_CAPTURE);
     $s = '';
     $iOffset = 0;
     foreach ($aMatches[1] as $aMatch) {
         $this->aParametersMap[] = $aMatch[0];
         $s .= substr($sQuery, $iOffset, $aMatch[1] - $iOffset - 1) . '?';
         $iOffset = $aMatch[1] + strlen($aMatch[0]);
     }
     $s .= substr($sQuery, $iOffset);
     $this->sStatementName = 'st_' . md5($sQuery);
     $this->oDb = $oDb;
     $this->oMySQLi = $oMySQLi;
     $s = 'PREPARE ' . $this->sStatementName . ' FROM ' . $this->oDb->escape($s);
     $oMySQLi->real_query($s) or burn('DatabaseException', sprintf(_WT("Failed to prepare the query with the following error:\n%s"), $oMySQLi->error));
 }
Example #6
0
 public function test(Request $request)
 {
     $db = new \mysqli('localhost', 'root', 'root', 'ryan');
     $count = 10;
     /*
     $category_map = array('/shop/art-design-books'=>'6','/shop/backpacks'=>'3','/shop/bags'=>'3','/shop/bar'=>'5','/shop/blocks'=>'8','/shop/books'=>'6','/shop/camping'=>'7','/shop/candles'=>'5','/shop/clocks'=>'5','/shop/coffee-&-tea'=>'5','/shop/cycling'=>'7','/shop/everyday-carry'=>'1','/shop/fragrance'=>'2','/shop/furniture'=>'5','/shop/gadgets'=>'4','/shop/garden'=>'5','/shop/handbags'=>'9','/shop/headphones'=>'4','/shop/home'=>'5','/shop/kitchen'=>'5','/shop/kitchen-knives'=>'5','/shop/knit-hats'=>'3','/shop/lighting'=>'5','/shop/mens-apparel'=>'10','/shop/men-s-shoes'=>'10','/shop/mugs'=>'5','/shop/office'=>'1','/shop/personal-care'=>'1','/shop/photography'=>'4','/shop/photography-books'=>'6','/shop/picnic'=>'5','/shop/pocket-knives'=>'7','/shop/socks'=>'3','/shop/speakers'=>'4','/shop/stationery'=>'1','/shop/storage-&-organization'=>'5','/shop/sunglasses'=>'3','/shop/toys-&-things'=>'8','/shop/watches'=>'3','/shop/water-bottles'=>'1','/shop/womens-apparel'=>'9','/shop/womens-shoes'=>'9');
     foreach($category_map as $from_where => $to_where)
     {
         $db->query("UPDATE `canopy_item_list` SET `to_where`='{$to_where}' WHERE `from_where`='{$from_where}'");
     }
     dd($category_map);
     */
     for ($i = 1; $i < 11; $i++) {
         $results = $db->query("SELECT * FROM `canopy_item_list` WHERE `title`<>'' AND `price`<>'' AND `image_data`<>'' AND `to_where` = {$i} AND `sent_at` IS NULL ORDER BY `id` ASC LIMIT 0,{$count}");
         while ($row = $results->fetch_assoc()) {
             $this->post->storeCurated($row, $i);
             $db->real_query("UPDATE `canopy_item_list` SET `sent_at` = CURRENT_TIMESTAMP WHERE id={$row['id']}");
         }
     }
     $db->close();
 }
Example #7
0
<?php

//LOGOWANIE TaWuA8kf
$haslo = $_GET['password'];
$login = $_GET['name'];
$servername = "db.zut.edu.pl";
$dbname = "gg36296";
$username = "gg36296";
$password = "TaWuA8kf";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else {
    $sql = "SELECT name,password FROM accountdata WHERE name LIKE '{$login}' AND password LIKE '{$haslo}' ";
    $conn->real_query($sql);
    $res = $conn->use_result();
    while ($row = $res->fetch_assoc()) {
        if ($login == $row['name'] && $haslo == $row['password']) {
            echo "xD";
        } else {
            echo "login or password is incorrect";
        }
    }
}
Example #8
0
<?php

$IP = "localhost";
$USER = "root";
$PASS = "root";
$BD = "shop";
$mysqli = new mysqli($IP, $USER, $PASS, $BD);
if ($mysqli->connect_errno) {
    echo "Falló la conexión con MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$mysqli->real_query("SELECT * FROM books");
$resultado = $mysqli->use_result();
while ($fila = $resultado->fetch_assoc()) {
    echo "Id = " . $fila['book_id'] . "<br>";
    echo "Titulo = " . $fila['title'] . "<br>";
    echo "Autor = " . $fila['author'] . "<br>";
    echo "Precio = " . $fila['price'] . "<br>";
    echo "<br>";
}
Example #9
0
 function callMySQLIProcedure($sql)
 {
     $mysqli = new mysqli(XOOPS_DB_HOST, XOOPS_DB_USER, XOOPS_DB_PASS, XOOPS_DB_NAME);
     $mysqli->real_query($sql);
     $result = $mysqli->store_result();
     $row = $result->fetch_assoc();
     $status = $row['status'];
     $mysqli->close();
     return $status;
 }
Example #10
0
<?php

$mysqli = new mysqli("localhost", "daohang", "e02b2943b3c6265b12da8f385f7cab75", "daohang");
/* check connection */
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
/* change character set to utf8 */
if (!$mysqli->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
    //printf("Current character set: %s\n", $mysqli->character_set_name());
}
$mysqli->real_query("select *from xinwenkeji  order by id asc");
$res = $mysqli->use_result();
$items = array();
while ($row = $res->fetch_assoc()) {
    //print_r($row);
    array_push($items, $row);
}
echo json_encode($items);
//echo $_GET['query'];
Example #11
0
File: DB.php Project: point/cassea
 /**
  * Выполнение SQL запроса.
  *
  * Если запрос вернет несколько наборов результатов(multi query)
  * будет обработан только первый. Все остальные будут проигнорированы,
  * а соединение с базой данных будет доступно для следующих запросов.
  *
  * Данный метод реккомендуется использовать для выполнения 
  * хранимых продцедур, которые возвращают один набор результатов.
  * Второй набор результатов OK/ERR будет автоматически проигнорирован.
  *
  * @throws DBException в случае возникновения ошибки в запросе
  * @param string $query SQL запрос
  * @param int $flags флаги для обработки результатов доступны следующие  флаги: {@link DB::USE_RESULT DB::USE_RESULT}, {@link DB::STORE_RESULT},
  *                      {@link DB::FETCH_NUM  DB::FETCH_NUM }, {@link DB::FETCH_ASSOC  DB::FETCH_ASSOC }, {@link DB::FETCH_BOTH  DB::FETCH_BOTH };
  * @return mixed массив результатов; affected_rows  в случает успешного "UPDATE"-одобного запроса; lastInsertedId в случае insert запроса.
  */
 public static function query($query, $flags = null)
 {
     //print_pre('==============================mysql:<b>'.$query.'</b>' );
     $r = self::$mysqli->real_query($query);
     if ($r === true) {
         // process flags
         $data_process = 'mysqli_store_result';
         if ($flags & DB::USE_RESULT) {
             $data_process = 'mysqli_use_result';
         }
         //var_dump($data_process);
         $resulttype = MYSQLI_ASSOC;
         if ($flags & DB::FETCH_NUM) {
             $resulttype = MYSQLI_NUM;
         } else {
             if ($flags & DB::FETCH_BOTH) {
                 $resulttype = MYSQLI_BOTH;
             }
         }
         $res = call_user_func($data_process, self::$mysqli);
         if (is_object($res)) {
             $data = array();
             while (($d = $res->fetch_array($resulttype)) !== null) {
                 $data[] = $d;
             }
         } else {
             if (strcmp(strtolower(substr(ltrim($query), 6)), 'insert')) {
                 $data = self::$mysqli->insert_id;
             } else {
                 $data = self::$mysqli->affected_rows;
             }
         }
         self::clearResultset($res);
         return $data;
     } else {
         throw new DBException(self::$mysqli->error, self::$mysqli->errno, $query);
     }
 }
Example #12
0
 public static function getDBSize($dbname, mysqli $mysqli)
 {
     $sql = "SELECT\n\t\t\tTABLE_SCHEMA AS db_name,\n\t\t\tCONCAT(TRUNCATE(SUM(data_length)/1024/1024,2),' MB') AS data_size,\n\t\t\tCONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),'MB') AS index_size\n\t\tFROM information_schema.tables WHERE TABLE_SCHEMA='{$dbname}'\n\t\tGROUP BY TABLE_SCHEMA\n\t\tORDER BY data_length DESC";
     if (!$mysqli->real_query($sql)) {
         if (self::$verbose) {
             echo 'getDBSize failed:' . $mysqli->error . "\n";
         }
         return false;
     }
     $result = $mysqli->store_result();
     if ($row = $result->fetch_assoc()) {
         return $row;
     }
     if (self::$verbose) {
         echo "Schema {$dbname} not exist\n";
     }
     return false;
 }
Example #13
0
 /**
  * Execute an SQL query.
  *
  * Wrapper around [mysqli::real_query](http://php.net/manual/en/mysqli.real-query.php), however on failure an
  * exception is thrown.
  *
  * @param string $query The SQL statement.
  */
 protected static function realQuery($query)
 {
     if (self::$logQueries) {
         $time0 = microtime(true);
         $ret = self::$mysqli->real_query($query);
         if ($ret === false) {
             throw new DataLayerException(self::$mysqli->errno, self::$mysqli->error, $query);
         }
         self::$queryLog[] = ['query' => $query, 'time' => microtime(true) - $time0];
     } else {
         $ret = self::$mysqli->real_query($query);
         if ($ret === false) {
             throw new DataLayerException(self::$mysqli->errno, self::$mysqli->error, $query);
         }
     }
 }
Example #14
0
<?php

$mysqli = new mysqli("localhost", "daohang", "e02b2943b3c6265b12da8f385f7cab75", "daohang");
/* check connection */
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
/* change character set to utf8 */
if (!$mysqli->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
    //printf("Current character set: %s\n", $mysqli->character_set_name());
}
$mysqli->real_query("SELECT * FROM xinwenyule ORDER BY id ASC");
$res = $mysqli->use_result();
//echo "Result set order...\n";
while ($row = $res->fetch_assoc()) {
    echo $row['title'] . $row['author'] . $row['link'] . '\\n';
    echo '<a href="' . $row['link'] . '" target="_blank">' . $row['title'] . ' by ' . $row['author'] . '</a>';
}
Example #15
0
 public function setUp()
 {
     if (!self::$mysql->real_query("TRUNCATE TABLE " . self::$DB_TABLE_NAME)) {
         throw new \Exception("Could not truncate table");
     }
 }
Example #16
0
if (!$mysqli->query("DROP TABLE IF EXISTS test") || !$mysqli->query("CREATE TABLE test(id INT)") || !$mysqli->query("INSERT INTO test(id) VALUES (1), (2), (3)")) {
    echo "Table creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$res = $mysqli->query("SELECT id FROM test ORDER BY id ASC");
echo "Reverse order...\n";
for ($row_no = $res->num_rows - 1; $row_no >= 0; $row_no--) {
    $res->data_seek($row_no);
    $row = $res->fetch_assoc();
    echo " id = " . $row['id'] . "\n";
}
echo "Result set order...\n";
$res->data_seek(1);
while ($row = $res->fetch_assoc()) {
    echo " id = " . $row['id'] . "\n";
}
$mysqli->real_query("SELECT id FROM test ORDER BY id ASC");
$res = $mysqli->use_result();
echo "Result set order...\n";
while ($row = $res->fetch_assoc()) {
    echo " id = " . $row['id'] . "\n";
}
if (!$mysqli->query("DROP TABLE IF EXISTS test") || !$mysqli->query("CREATE TABLE test(id INT, label CHAR(1))") || !$mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a')")) {
    echo "Table creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$res = $mysqli->query("SELECT id, label FROM test WHERE id = 1");
$row = $res->fetch_assoc();
printf("id = %s (%s)\n", $row['id'], gettype($row['id']));
printf("label = %s (%s)\n", $row['label'], gettype($row['label']));
/* Prepared statement, stage 1: prepare */
if (!($stmt = $mysqli->prepare("INSERT INTO test(id) VALUES (?)"))) {
    echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
<?php

if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
    die(__('You must run this script from your localhost (to stop hackers)'));
}
if (isset($_POST['action']) && $_POST['action'] == 'convert') {
    $mysqli = new mysqli($_POST['hostname'], $_POST['username'], $_POST['password'], $_POST['database']);
    if ($mysqli->connect_error) {
        die(__('Connect Error') . ' (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
    }
    // { products
    $query = $mysqli->real_query('select * from wp_wpsc_product_list');
    if (!($result = $mysqli->use_result())) {
        die(__('error retrieving products list'));
    }
    $products = array();
    while ($row = $result->fetch_array()) {
        $products[] = array('id' => $row['id'], 'name' => $row['name'], 'product_type_id' => 1, 'image_default' => 0, 'enabled' => $row['active'], 'date_created' => $row['date_added'], 'data_fields' => json_encode(array(array('n' => 'description', 'v' => $row['description']), array('n' => 'additional_description', 'v' => $row['additional_description']))), 'images_directory' => '/products/product-images/' . $row['id'], 'online_store_fields' => json_encode(array('_price' => $row['price'], '_weight(kg)' => $row['weight'], '_vatfree' => $row['notax'])));
    }
    // }
    // { images
    $images = array();
    $query2 = $mysqli->real_query('select * from wp_wpsc_product_images order by product_id,image_order');
    if (!($result = $mysqli->use_result())) {
        die(__('error retrieving products list'));
    }
    while ($row = $result->fetch_array()) {
        if ($row['image_order'] == '') {
            $row['image_order'] = '_';
        }
        $images[] = array($row['product_id'] . '/' . $row['image_order'] . $row['image'], $_POST['url'] . 'wp-content/uploads/wpsc/product_images/' . $row['image']);