Пэлт
всем привет!
я ещё думаю что выбрать для работы с БДPHP:
$sql = «SELECT * FROM pidors WHERE login = ? AND password = ? LIMIT 1»; $stmt = $pdo->prepare($sql); $stmt->execute([$login, $password]); $data = $stmt->fetchAll();Напишите, пожалуйста эти строки кода, как бы это делалось без PDO.
Я про подготовленные запросы в бд на мускли.
Drunkenmunky
https://www.php.net/manual/ru/mysqli-stmt.get-result.php
lastdays
Орнул с названия таблицы))
p.s. так вот, как ты о своих клиентах
MouseZver
Знайте, вы пидоры !!!
— Добавлено —PHP:
$stmt = $db -> prepare( ‘SELECT * FROM table WHERE column1 = :user’, [ ‘user’ => ‘pidor’ ] ); echo ( $stmt -> rowCount() ? ‘есть пидор’ : ‘нету пидора’ );— Добавлено —
а ну ок.
PHP:
<?php declare ( strict_types = 1 ); /* @ Author: MouseZver @ Email: mouse-zver@xaker.ru @ url-source: http://github.com/MouseZver/Lerma @ php-version 7.4 */ namespace NouvuDatabaseLermaExt; use NouvuDatabase{ Lerma, InterfaceDriver }; use Error; use NouvuConfigConfig; final class Mysql implements InterfaceDriver { private $statement = null; private $query = null; private $result; private Lerma $lerma; private Config $config; private string $driver; private mysqli $connect; public function __construct ( Lerma $lerma, Config $config, string $driver ) { $this -> lerma = $lerma; $this -> config = $config; $this -> driver = $driver; $this -> params = $this -> config -> get( «drivers.{$this -> driver}» ); $this -> connect(); } private function connect() { try { $this -> connect = new mysqli( $this -> params[‘host’], $this -> params[‘username’], $this -> params[‘password’], $this -> params[‘dbname’], ( int ) $this -> params[‘port’] ); if ( $this -> connect -> connect_error ) { throw new Error( sprintf ( $this -> config -> get( «errMessage.connect.{$this -> driver}» ), $this -> connect -> connect_errno, $this -> connect -> connect_error ) ); } $this -> connect -> set_charset( $this -> params[‘charset’] ); } catch ( mysqli_sql_exception $e ) { $this -> config -> get( «ShemaExceptionConnect.{$this -> driver}» )( $e ); } } public function query( string $sql ): void { $this -> connect -> ping() ?: $this -> connect(); $this -> query = $this -> connect -> query( $sql ); } public function prepare( string $sql ): void { $this -> connect -> ping() ?: $this -> connect(); $this -> statement = $this -> connect -> prepare( $sql ); } public function fetch( int $int ) { switch ( $int ) { case Lerma :: FETCH_NUM: { return $this -> result() -> fetch_array( MYSQLI_NUM ); } case Lerma :: FETCH_ASSOC: { return $this -> result() -> fetch_array( MYSQLI_ASSOC ); } case Lerma :: FETCH_OBJ: { return $this -> result() -> fetch_object(); } case Lerma :: MYSQL_FETCH_BIND: { return $this -> statement -> fetch(); } { } default: { return null; } } } public function fetchAll( int $int ) { switch ( $int ) { case Lerma :: FETCH_NUM: { return $this -> result() -> fetch_all( MYSQLI_NUM ); break; } case Lerma :: FETCH_ASSOC: { return $this -> result() -> fetch_all( MYSQLI_ASSOC ); break; } { return $thiss -> result() -> fetch_fields(); break; } default: { return null; } } } public function columnCount(): int { return $this -> connect -> field_count; } public function rowCount(): int { return $this -> result() -> num_rows; } public function InsertID(): int { return $this -> connect -> insert_id; } public function rollBack( …$rollback ): bool { return $this -> connect -> rollback( …$rollback ); } public function beginTransaction( …$rollback ): bool { return $this -> connect -> begin_transaction( …$rollback ); } public function commit( …$commit ): bool { return $this -> connect -> commit( …$commit ); } public function isError(): void { $obj = $this -> statement ?: $this -> connect; if ( $obj -> errno ) { throw new Error( $obj -> error ); } } { $this -> result = null; $for = [ » ]; $count = 0; foreach ( $this -> lerma -> executeHolders( $binding[0] ) AS $args ) { $short = [ ‘integer’ => ‘i’, ‘double’ => ‘d’, ‘string’ => ‘s’, ‘NULL’ => ‘s’ ]; { throw new Error( «Invalid type {$type}« ); } $for[0] .= $short[$type]; $count++; } for ( $i = 0; $i < $count; $for[] = &${ ‘bind_’ . $i++ } ){} $this -> statement -> bind_param( …$for ); foreach ( $binding AS $items ) { $items = $this -> lerma -> executeHolders( $items ); $this -> statement -> execute(); } } public function bindResult( $result ) { { return $this -> statement -> bind_result( …$result ); } throw new Error( $this -> config -> get( ‘errMessage.statement.bindResult’ ) ); } public function close(): InterfaceDriver { { $close -> close(); } $this -> statement = $this -> query = $this -> result = null; return $this; } /* — Определение типа запроса в базу данных */ protected function result() { { return $this -> result ?: $this -> result = $this -> statement -> get_result(); } return $this -> query; } }