{% else-1 %}
Обновить
* Тема закрыта!
1. [автор] (7 май 2013, 23:52) [0/0] [0] [спам] [под]

Fatal error: Uncaught exception \'PDOException\' with message \'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'LIMIT 1\' at line 1\' in Z:\\home\\new\\www\\dbPDO.php:54 Stack trace: #0 Z:\\home\\new\\www\\dbPDO.php(54): PDOStatement->execute(Array) #1 Z:\\home\\new\\www\\dbPDO.php(27): PDOStatement_->execute(Array) #2 Z:\\home\\new\\www\\dbPDO.php(38): PDO_->query(\'SELECT * FROM `...\', Array) #3 Z:\\home\\new\\www\\forum\\my_t.php(57): PDO_->queryFetch(\'SELECT * FROM `...\', Array) #4 {main} thrown in Z:\\home\\new\\www\\dbPDO.php on line 54

Как исправить?

2. (8 май 2013, 00:13) [0/0] [0] [спам] [под]

запрос бы лудше показал*

3. [автор] (8 май 2013, 00:19) [0/0] [0] [спам] [под]
Призрак,

<?
define(\'inc\',$_SERVER[\'DOCUMENT_ROOT\'].\'/\');
define (\'DBHOST\', \'localhost\');
define (\'DBPORT\', \'3306\');
define (\'DBNAME\', \'mail33_soc\');
define (\'DBUSER\', \'root\');
define (\'DBPASS\', \'\');
if (!class_exists(\'PDO\'))
die(\'Fatal Error: Для работы нужна поддержка PDO.\');
/* клон класса PDO */
class PDO_ extends PDO {
function __construct($dsn, $username, $password) {
parent :: __construct($dsn, $username, $password);
$this -> setAttribute(PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION);
$this -> setAttribute(PDO :: ATTR_DEFAULT_FETCH_MODE, PDO :: FETCH_ASSOC);
}

function prepare($sql) {
$stmt = parent :: prepare($sql, array(
PDO :: ATTR_STATEMENT_CLASS => array(\'PDOStatement_\')
));
return $stmt;
}
/* аналог запроса mysql_query */
function query($sql, $params = array()) {
$stmt = $this -> prepare($sql);
$stmt -> execute($params);
return $stmt;
}
/* аналог mysql_result */
function querySingle($sql, $params = array()) {
$stmt = $this -> query($sql, $params);
$stmt -> execute($params);
return $stmt -> fetchColumn(0);
}
/* аналог mysql_fetch_assoc(mysql_query */
function queryFetch($sql, $params = array()) {
$stmt = $this -> query($sql, $params);
$stmt -> execute($params);
return $stmt -> fetch();
}
}
// ----------------------------------------------------//
class PDOStatement_ extends PDOStatement {
function execute($params = array()) {
if (func_num_args() == 1) {
$params = func_get_arg(0);
} else {
$params = func_get_args();
}
if (!is_array($params)) {
$params = array($params);
}
parent :: execute($params);
return $this;
}

function fetchSingle() {
return $this -> fetchColumn(0);
}

function fetchAssoc() {
$this -> setFetchMode(PDO :: FETCH_NUM);
$data = array();
while ($row = $this -> fetch()) {
$data[$row[0]] = $row[1];
}
return $data;
}
}

class DB {
static $dbs;
public function __construct() {
try {
self :: $dbs = new PDO_(\'mysql:host=\' . DBHOST . \';port=\' . DBPORT . \';dbname=\' . DBNAME, DBUSER, DBPASS);
self :: $dbs -> exec(\'SET CHARACTER SET utf8\');
self :: $dbs -> exec(\'SET NAMES utf8\');
}
catch (PDOException $e) {
die(\'Connection failed: \' . $e -> getMessage());
}
}
}

$db = new DB();
?>

Файл DBpdo.php

А запрос
$post=DB::$dbs->queryFetch(\"SELECT * FROM `forum_p` WHERE `id_them` =? AND `id_razdel` =? AND `id_forum` =? ORDER BY `time` DESC LIMIT 1\",array($them[\'id\'],$razdel[\'id\'],$forum[\'id\']));
$ank2=DB::$dbs->queryFetch(\"SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1\",array($post[\'id_user\']));

4. (8 май 2013, 01:42) [1/0] [1] [спам] [под]

ну вот
$ank2=DB::$dbs->queryFetch(\"SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1\",array($post[\'id_user\']));
а должно быть так
$ank2=DB::$dbs->queryFetch(\"SELECT * FROM `user` WHERE `id` = ? LIMIT 1\",array($post[\'id_user\']));

5. [автор] (8 май 2013, 01:44) [0/0] [0] [спам] [под]
Призрак,

Ясно, понятно, биг спс. *


Изм. 1 раз. / Посл. изм. (8 май 2013, 01:45)
6. [автор] (8 май 2013, 01:45) [0/0] [0] [спам] [под]

Тема закрыта для обсуждения! *

  • 1 из 1
Подписаны: 1
Скачать тему | Файлы темы | Фильтр сообщений