Hallo zusammen,
ich habe meine Software von den alten mysql_ Funktionen auf PDO umgebaut und auf meinem Localhost mit PHP 5.5.3 funktioniert alles ohne Probleme.
Ich verwende eine fertige PHP PDO Klasse.
Wenn ich nun das ganze auf meinen Server mit PHP 5.4.17 spiele, erhalte ich bei manchen Abfragen einen SQL Fehler, den ich nicht ganz zuordnen kann:
Unhandled Exception.
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 ''10'' at line 1
Die Abfrage dazu sieht wie folgt aus:
Ich habe mal bisschen gegoogled und eventuell besteht ein Bug in der alten PHP Version mit Maskierung des Limits, dennoch würde ich gerne eure Meinung wissen ob ich hier irgendwas grundlegendes falsch gemacht habe.
Wie gesagt, auf dem Localhost läuft alles.
Die dazugehörige PDO-Klase instanziert wie folgt:
Wenn ich die Zeile
auf FALSE setze, kommt kein Fehler, dafür ist das System so langsam, dass ich mir nebenher ein Spiegelei braten könnte.
ich habe meine Software von den alten mysql_ Funktionen auf PDO umgebaut und auf meinem Localhost mit PHP 5.5.3 funktioniert alles ohne Probleme.
Ich verwende eine fertige PHP PDO Klasse.
Wenn ich nun das ganze auf meinen Server mit PHP 5.4.17 spiele, erhalte ich bei manchen Abfragen einen SQL Fehler, den ich nicht ganz zuordnen kann:
Unhandled Exception.
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 ''10'' at line 1
Die Abfrage dazu sieht wie folgt aus:
PHP-Code:
public function get_premium_products($project = 1, $premiumtype, $limit = 10, $maincatter = "")
{ $this->dbobj->bind("project_id", $project);
$this->dbobj->bind("premiumtype", $premiumtype);
$this->dbobj->bind("limit", $limit);
$sql = "SELECT * FROM product_main WHERE project = :project_id AND activation = 1 AND premium = :premiumtype AND premium_expire > ".time()." ";
if ($maincatter != "")
{ $this->dbobj->bind("maincatter", $maincatter);
$sql .= " AND maincat = :maincatter ";
}
$sql .= " ORDER BY RAND() LIMIT 0, :limit ";
$result = $this->dbobj->query($sql);
Wie gesagt, auf dem Localhost läuft alles.
Die dazugehörige PDO-Klase instanziert wie folgt:
PHP-Code:
private function Connect()
{
$this->settings = parse_ini_file("settings.ini.php");
$dsn = 'mysql:dbname='.$this->settings["dbname"].';host='.$this->settings["host"].'';
try
{
# Read settings from INI file, set UTF8
$this->pdo = new PDO($dsn, $this->settings["user"], $this->settings["password"], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_PERSISTENT => true));
# We can now log any exceptions on Fatal error.
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# Disable emulation of prepared statements, use REAL prepared statements instead.
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
# Connection succeeded, set the boolean to true.
$this->bConnected = true;
}
catch (PDOException $e)
{
# Write into log
echo $this->ExceptionLog($e->getMessage());
die();
}
}
PHP-Code:
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
Kommentar