can any one help me to use the mysql inbuilt function in cakePHP?????
If you don't want to use
$this->Model->query($yoursql);
Then there's still another way for some mysql functions such as concat,date_format
$this->Model->find($findtype,array('fields'=>array('concat (column1,column2,...) as con','date_format(...) as mydate'),'conditions'=>...));
There is an example of how to use CONCAT in the book. I imagine you would be able to extend the syntax to use the other MySql functions as required.
Related
I'm creating an API for POIs and use the POINT-Type to store the coordinates.
As my company uses CakePHP I have to write a migration-script with Phinx.
But I don't have any Idea how to correctly create a column with the POINT-Type.
Sure, I just could make an "ALTER TABLE ..." in a handwritten Query, but maybe there is a better way?
Versions:
Cake: 3.4.7
Phinx: 0.6.5
MySQL: 5.7.18
Phinx Does not provide an adapter for POINT yet.
You should create your query manually.
See also Unable to seed data with POINT datatype #999
Just use "point" as you would use any other datatype as the second parameter of addColumn().
It's just not documented yet.
Credits for this solution are going to #ndm;
I just think it's worth putting this as answer instead as a comment.
Looks like Phinx supports point types for quite some time now (the docs are not up to date)... try to use \Phinx\Db\Adapter\AdapterInterface::PHINX_TYPE_POINT as the type
I want to use the SQL clause "Use index('index_name')" to an ActiveRecord query, does anyone knows a good way to do it with Activerecord
I wanted to avoid adding string directly to the query.
I use this in my models:
def self.use_index(index)
from("#{self.table_name} USE INDEX(#{index})")
end
Just as a follow up, I've just implemented a solution based on James' above but used a scope instead:
scope :force_index, -> (index) {
from("#{table_name} FORCE INDEX(#{index})")
}
I have more queries in mysql, but i not use the $this->query(), because I do not need to create arrays. in cakephp there any way? the function this->query force to go through the model.
thanks
You can try with DboSource query method
Is there a mysql equivalent of pg_query_params?
Check mysqli_prepare() or PDOStatement(). Both are a bit different, but still use a prepared statement.
I am using prepared statements with mysqli(); to insert and retrieve data on my website also i used bind_param so i don't add variables directly into the query.I used strip_tags to clean any inputs what else should i look out for ?
Don't use strip_tags() on database input: use htmlentites() (or urlencode() where appropriate) on browser output.