2016-07-12 15 views
0

Ich habe ein Problem mit der JDatabase in Joomla. Ich folge einige Beispiele aus https://docs.joomla.org/Secure_coding_guidelines#Secure_on_searchJoomla-Datenbank-Abfrage mit Platzhalter

Mein Code:

$db = JFactory::getDbo(); 
$query = $db->getQuery (true); 

$query->select ('*'); 
$query->from ($db->quoteName ('#__someTable')); 

$search = $db->escape('someString', true) . '%'; 

$query->where ($db->quoteName ('someField') . ' LIKE ' . $db->quote($search, false)); 

Dieses in einem SQL-Fehler endet:

1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3 SQL=SELECT * FROM `frb6z_opensourcepage_productscomponent` WHERE 

Die ‚where'-Klausel einfach ist gestreift des Erhaltens.

Was mache ich falsch?

Ich möchte Zeilen abfragen, in denen 'someField' mit 'someString' beginnt.

Var_dump und der Abfrage Verlassen vor dem Ausführen der Abfrage gibt mir, dass:

object(JDatabaseQueryMysqli)#956 (24) { 
["offset":protected]=> NULL 
["limit":protected]=> NULL 
["db":protected]=> object(JDatabaseDriverMysqli)#15 (23) { 
    ["name"]=> string(6) "mysqli" 
    ["serverType"]=> string(5) "mysql" 
    ["connection":protected]=> object(mysqli)#16 (19) { 
     ["affected_rows"]=> int(1) 
     ["client_info"]=> string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: fd3bfdab644600c96b25beaf69d021447b7b4ec5 $" 
     ["client_version"]=> int(50012) 
     ["connect_errno"]=> int(0) 
     ["connect_error"]=> NULL 
     ["errno"]=> int(0) 
     ["error"]=> string(0) "" 
     ["error_list"]=> array(0) { } 
     ["field_count"]=> int(0) 
     ["host_info"]=> string(25) "Localhost via UNIX socket" 
     ["info"]=> NULL 
     ["insert_id"]=> int(0) 
     ["server_info"]=> string(21) "5.5.5-10.1.13-MariaDB" 
     ["server_version"]=> int(50505) 
     ["stat"]=> string(142) "Uptime: 685930 Threads: 1 Questions: 1395565 Slow queries: 0 Opens: 11271 Flush tables: 1 Open tables: 64 Queries per second avg: 2.034" 
     ["sqlstate"]=> string(5) "00000" 
     ["protocol_version"]=> int(10) 
     ["thread_id"]=> int(1406) 
     ["warning_count"]=> int(0) } 
    ["nameQuote":protected]=> string(1) "`" 
    ["nullDate":protected]=> string(19) "0000-00-00 00:00:00" 
    ["_database":"JDatabaseDriver":private]=> string(6) "joomla" 
    ["count":protected]=> int(12889) 
    ["cursor":protected]=> bool(true) 
    ["debug":protected]=> bool(false) 
    ["limit":protected]=> int(0) 
    ["log":protected]=> array(0) { } 
    ["timings":protected]=> array(0) { } 
    ["callStacks":protected]=> array(0) { } 
    ["offset":protected]=> int(0) 
    ["options":protected]=> array(9) { 
     ["driver"]=> string(6) "mysqli" 
     ["host"]=> string(9) "localhost" 
     ["user"]=> string(4) "root" 
     ["password"]=> string(0) "" 
     ["database"]=> string(6) "joomla" 
     ["prefix"]=> string(6) "frb6z_" 
     ["select"]=> bool(true) 
     ["port"]=> int(3306) 
     ["socket"]=> NULL } 
    ["sql":protected]=> object(JDatabaseQueryMysqli)#854 (24) { 
     ["offset":protected]=> int(0) 
     ["limit":protected]=> int(0) 
     ["db":protected]=> *RECURSION* 
     ["sql":protected]=> NULL 
     ["type":protected]=> string(6) "insert" 
     ["element":protected]=> NULL 
     ["select":protected]=> NULL 
     ["delete":protected]=> NULL 
     ["update":protected]=> NULL 
     ["insert":protected]=> object(JDatabaseQueryElement)#781 (3) { 
      ["name":protected]=> string(11) "INSERT INTO" 
      ["elements":protected]=> array(1) { 
       [0]=> string(48) "`#__opensourcepage_product_mm_productscomponent`" } 
      ["glue":protected]=> string(1) "," } 
     ["from":protected]=> NULL 
     ["join":protected]=> NULL 
     ["set":protected]=> NULL 
     ["where":protected]=> NULL 
     ["group":protected]=> NULL 
     ["having":protected]=> NULL 
     ["columns":protected]=> object(JDatabaseQueryElement)#937 (3) { 
      ["name":protected]=> string(2) "()" 
      ["elements":protected]=> array(2) { 
       [0]=> string(11) "`uid_local`" 
       [1]=> string(13) "`uid_foreign`" } 
      ["glue":protected]=> string(1) "," } 
     ["values":protected]=> object(JDatabaseQueryElement)#824 (3) { 
      ["name":protected]=> string(2) "()" 
      ["elements":protected]=> array(1) { 
       [0]=> string(11) "'169','248'" } 
      ["glue":protected]=> string(3) "),(" } 
     ["order":protected]=> NULL 
     ["autoIncrementField":protected]=> bool(false) 
     ["call":protected]=> NULL 
     ["exec":protected]=> NULL 
     ["union":protected]=> NULL 
     ["unionAll":protected]=> NULL } 
    ["tablePrefix":protected]=> string(6) "frb6z_" 
    ["utf":protected]=> bool(true) 
    ["utf8mb4":protected]=> bool(true) 
    ["errorNum":protected]=> int(0) 
    ["errorMsg":protected]=> string(0) "" 
    ["transactionDepth":protected]=> int(0) 
    ["disconnectHandlers":protected]=> array(0) { } } 
["sql":protected]=> NULL 
["type":protected]=> string(6) "select" 
["element":protected]=> NULL 
["select":protected]=> object(JDatabaseQueryElement)#839 (3) { 
    ["name":protected]=> string(6) "SELECT" 
    ["elements":protected]=> array(1) { 
     [0]=> string(1) "*" } 
    ["glue":protected]=> string(1) "," } 
["delete":protected]=> NULL 
["update":protected]=> NULL 
["insert":protected]=> NULL 
["from":protected]=> object(JDatabaseQueryElement)#789 (3) { 
    ["name":protected]=> string(4) "FROM" 
    ["elements":protected]=> array(1) { 
     [0]=> string(37) "`#__opensourcepage_productscomponent`" } 
    ["glue":protected]=> string(1) "," } 
["join":protected]=> NULL 
["set":protected]=> NULL 
["where":protected]=> object(JDatabaseQueryElement)#953 (3) { 
    ["name":protected]=> string(5) "WHERE" 
    ["elements":protected]=> array(1) { 
     [0]=> string(31) "`component_id` LIKE 'Product-%'" } 
    ["glue":protected]=> string(5) " AND " } 
["group":protected]=> NULL 
["having":protected]=> NULL 
["columns":protected]=> NULL 
["values":protected]=> NULL 
["order":protected]=> NULL 
["autoIncrementField":protected]=> NULL 
["call":protected]=> NULL 
["exec":protected]=> NULL 
["union":protected]=> NULL 
["unionAll":protected]=> NULL } 

Bis jetzt alles normal scheint ...

+0

Ich benutzte verschiedene Feldnamen und Tabelle und konnte das Ergebnis erhalten. Können Sie Ihre Abfrage auf diese Weise var_dump und geben Sie die Ausgabe hier. var_dump ($ query); Ausfahrt; kurz bevor Sie setquery ausführen oder verwenden. –

+0

Das sieht gut aus. Können Sie Ihre vollständige DB-Abfrage entweder hier oder in pastebin.com hinzufügen –

Antwort

0

Ok, ich den Fehler in meinem Code gefunden woanders . Also diese Abfrage war wirklich gut, aber eine andere direkt danach ging schief. Danke, dass Sie es trotzdem versuchen ...

+0

Dies ist keine Antwort. Es gab einen Codefehler, den niemand kennt. Aber Sie können dies als Kommentar weitergeben. –

+0

Ok, tut mir leid. Ich bin ziemlich neu dazu. Das nächste Mal, wenn ich weiß ... – user3384516