How can i debug the query building my table - php

I'm using jQuery DataTables Editor with PHP library and I want to see the final query that is used to build my table. I looked in the following files:
Editor-PHP-1.5.6/php/Database/Driver/Mysql/Result.php
Editor-PHP-1.5.6/php/Database/Driver/Mysql/Query.php
and I saw many functions calling each other like "ping-pong" and couldn't find the way to see the final query.
I want to check my joins in the query. Where can i find it?

I appreciate this is old, and is referring to Editor 1.5, but since Editor 1.6 you can simply add ->debug(true) into the server's scripts. For more information, see the release notes for 1.6 : https://editor.datatables.net/download/1.6.0 .

Related

Getting content from search box finding it in database

I know this is a broad question, but seriously.. I really couldnt find and answer for this, only the LIKE keyword that checks if it contains it..
I want to look for something in a db if it contains it, starts with it, or ends with it and by order by the most populaur result?
I have a search box in bootstrap and when the content is changed, an ajax request is sent for the new content..
It there a way to do this.
Using LIKE is nothing. Use full text search in mysql. There are disadvantages: myisam required, for char/varchar/text fields only. See more info here:
https://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
A great alternative is using a real search engine such as Elasticsearch, built on the top of Apache Lucene: fast, relevant, flexible, adaptable, works with json api. See more info here: https://www.elastic.co/products/elasticsearch

php code drupal database get

Ok I am using drupal 7.
I need to get information out of some tables so I can read them in a iPhone app. I found out I need a php code to convert a table to json format. I need the code to go to a database "x" then to table "y". Then list entity_id and name from all the fields. This will be a read only. I don't know the first thing about php code. Can anyone point me in the right direction? Thanks
Follow the steps :-
Learns PHP :-)
learn how drupal works
Learn Drupal hooks
Drupal query.
Once you are inside drupal you dont need to coonect to drupal database, its handled by Drupal.
After this you can use hook_menu and in call back function you can return required JSON output.
Use that link in your application.
Chheers!!!

Slow searching in php

I'm new in php and mysql. Now i facing a problem is i need search data in a large database, but it take more than 3 minute to search a word, sometime the browser show timeout. I using technique FULLTEXT to do a searching, so any solution to decrease the searching time?
create index for the table field which you will prefer subsequently, even it take some memory space query result should return best results within less time.
This doesn't answer your question directly but is a suggestion:
I had the same problem with full text search so I switched to SOLR:
http://lucene.apache.org/solr/
It's a search server based on the Lucene library written in Java. It's used by some of the largest scale websites:
http://wiki.apache.org/solr/PublicServers
So speed and scalability isn't an issue. You don't need to know Java to implement it however. It offers a REST interface that you can query and even gives the option to return the search results in PHP array format.
Here's the official tutorial:
https://builds.apache.org/job/Solr-trunk/javadoc/doc-files/tutorial.html
SOLR searches through indexed files so you need to get your database contents into xml or json files. You can use the Data Import Handler extension for that:
http://wiki.apache.org/solr/DataImportHandler
To query the REST interface you can simply use get_file_contents() php function or CURL. Or the PHP sdk for SOLR:
http://wiki.apache.org/solr/SolPHP
Depends on how big your database is. Adding an index for the field you are searching is the first thing to do.
I have been into the same problem and adding an index for the field worked great.

Table Filtering with dropdown menu with jqGrid and php

I just wondering if i can create something similar to this but with javascript code cause i don't wanna buy the whole Jgrid php library.
I talk about the 4th column (drop down menu filter).
I have just create the first grid as they say here
Also i read some similar questions here but the most of them are based on ASP .net
If this can be achieved please give me some hints..
Thanks in advance.
What you need is just toolbar searching together with the common searching configuration. All the feature exists in the free open source version of jqGrid. Look at the demo. I hope it does what you need.

Zend_Search_Lucene query parsing problem

Here's the setup, I have a Lucene Index and it works well with the 2,000 documents I have indexed. I have been using Luke (Lucene Index Toolbox, v.0.9.2) to debug queries, and am using ZF 1.9.
The layout for my Lucene Index is as follows:
I = Indexed
T = Tokenized
S = Stored
Fields:
author - ITS
category - ITS
publication - ITS
publicationdate - IS
summary - ITS
title - ITS
Basically I have a form that is searchable by the above fields, letting you mix and match any of the above information, and will parse it into a zend luceue query. That is not the problem, the problem is when I start combining terms, the "optimize" method that fires within the find causes the query to just disappear.
Here is an example search I am running right now:
Form Version:
Title: test title
Publication: publication name
Lucene Query Parse:
+(title:test title) +(publication:publication name)
Now if I take this query string, and slap it into LUKE, and hit "Search", it returns the results just fine. When I use the Query Find method, it bombs out. So I did a little research into how it functions and found a problem (I believe)
First off, heres the actual lines of code that does the searching:
$searchQuery = "+(title:test title) +(publication:publication name)";
$hits = new ArrayObject($this->index->find($searchQuery));
It's a simplified version of the actual code, but thats what it generates.
Now heres what I've noticed after some debugging, the "optimize" method just destroys the query itself. I created the following code:
$rewrite = $searchQuery->rewrite($this->index);
$optimize = $searchQuery->rewrite($this->index)->optimize($this->index);
echo "======<br/>";
echo "Original: ".$searchQuery."<br/>";
echo "Rewrite: ".$rewrite."<br/>";
echo "Optimized + Rewrite: ".$optimize."<br/>";
echo "======<br/>";
Which outputs the following text:
======
Original: +(title:test title) +(publication:publication name)
Rewrite: +(title:test title) +(publication:publication name)
Optimized + Rewrite:
======
Notice how the 3rd output is completely empty. It appears that the Rewrite & Optimize on the query is causing the query string to just empty itself.
Does anyone have any idea why the optimize method seems to just be removing my query all together? Am I missing a filter or some sort of interface that might need to be parsed? All of the queries work perfectly when I paste them into LUKE and run them against the index by hand, but something silly is going on with the way Zend is parsing the query to do the search.
Any help is appreciated.
I will be quite frank, Zend_Search_Lucene (ZSL) is buggy and not maintained since a long time now.
It is also conceptually wrong. Let me explain why:
Search engines are there to reply fast to search queries, the problem with ZSL is that it is implemented in pure PHP. It means that at every query, all indexes files are read and reloaded again, continuously. It can't be fast.
There is nothing wrong with Lucene itself, there is even a very good alternative named Solr which is based on Lucene: it is a search server implemented in Java which can index and reply to all your Lucene queries. Because of the server nature of Solr, you don't suffer of poor performance by reloading all the Lucene files again and again.
This is somewhat different that what you asked, I waited two years for my ZSL bugs to be solved, it's now the case using Solr :)

Categories