i am working on a project that need to work with spatial object in mysql and i choose redbeanphp as ORM system in this project. i found redbeanphp so terrific and awesome.
i search in google and found this link that say bindFunc method can help me in working with spatial object but i cannot find any example for using this method.
how this method work and how can i use this method?
According to the database part of that website you linked:
As of RedBeanPHP 4.1 you can bind an SQL function to a column. This is
useful for wrapping values when reading from / writing to the
database. For instance, to use MySQL spatial data types you need to
prepare the columns like this:
R::bindFunc( 'read', 'location.point', 'asText' );
R::bindFunc( 'write', 'location.point', 'GeomFromText' );
$location = R::dispense( 'location' );
$location->point = 'POINT(14 6)';
//inserts using GeomFromText() function
R::store( $location );
//to unbind a function, pass NULL:
R::bindFunc( 'read', 'location.point', NULL );
This function was added to support spatial datatypes in MySQL as shown above. The documentation isn't amazing, so I recommend looking at the source code on Github if you want to dig in deeper.
Related
How can i create safe string in yii, if i want to save multiple data?
This is my code:
$builder = Yii::app()->db->schema->commandBuilder;
$command = $builder->createMultipleInsertCommand('ewl_team_user', array(
array('user_name'=>'record1', 'user_desc'=>'leírás','team_id'=>1),
array('user_name'=>'record2', 'user_desc'=>'leírás','team_id'=>1),
array('user_name'=>'record3', 'user_desc'=>'leírás','team_id'=>1),
));
How can i use PDO params in this code?
Where should i write this part?
'params'=>array(':t'=>$data)
As I said in the comments, CDbCommandBuilder#createMultipleInsertCommand does not have any params argument. So the better way is to use CActiveRecord for saving data. First, you need to generate Model from table entity by Gii tools. If you are not familiar with Gii, refer this link. Then you can instantiate any number of objects, assign desired values to attributes, and finally save them.
I'm using jenssegers/laravel-mongodb package for using MongoDB with Laravel:
And I'm trying to implement text search with MongoDB using this command:
db.place.find({$text:{$search:"hotel"}})
But I don't know how to translate this query to using it with above package and Laravel.
Well, how funny, I just found out the answer. Here is the code to get the result from text search:
\DB::collection('place')->raw()->find(array('$text'=>array('$search'=>'hotel')))->getNext();
You can use whereRaw method.
Place::whereRaw(['$text' => ['$search' => 'hotel']])->get();
You can even make use of laravel query scope for defining common sets of constraints that you may easily re-use throughout your application.
Place Model
public function scopeContains($query, $search)
{
return $query->whereRaw(['$text' => ['$search' => $search]]);
}
Place Controller
Place::contains('hotel')->get();
I want to save results to cache but datamapper result objects is huge array.
I want to get only my query results without other data that referenced codeigniter data (models/configs/languages/etc..)
How can do this?
I searched on SO, internet and manual page (http://datamapper.wanwizard.eu/) but i couldnt find anything..
If you just want to access the core information about your records, try using the array extension here: http://datamapper.wanwizard.eu/pages/extensions/array.html
This allows you to run something like:
$objects-> all_to_array();
... which returns an array of objects, with all properties, but without the models/configs/languages &c. that you mention.
I want to addition some tips on #sevenpointsix answer
If you are using include_related, you have to specify columns like following (relation_column):
$fields = array('id', 'title', 'user_firstname', 'user_lastname', 'category_name');
$posts->get()->all_to_array($fields);
I'm creating a behavior that log to a table the sql query executed by a particular Model in a controller. Looking for a method to return me the sql query executed for a particular finder method (like $this->MyModel->find('all') ) I found on the bakery that I can use $this->MyModel->find('sql'), but doesn't work for me. Someone knows how can I achieve this?
Thanks in advance
You can put this function in your app_model.php:
function getLastQueries()
{
$dbo = $this->getDatasource();
$logs = $dbo->_queriesLog;
return $logs;
}
And call it from any model ($this->getLastQueries()) or controller ($this->Model->getLastQueries()) to get them.
$this->Model->find('sql') is not supported natively by Cake. You have to follow the rest of the instructions in the Bakery article for installing a new DBO driver, and adding support for the find('sql') method in your AppModel. Once you do this, it should be able to get you what you're looking for.
http://bakery.cakephp.org/articles/grant_cox/2008/06/23/get-the-find-query-sql-rather-than-query-result
I want to save an object or form to the database. Only I can't find the easiest (or normal) way for how to do this.
I found a lot of tutorials, but none seem to be easy or current. Can someone please help me with this?
I use version 1.9.3 of the Zend Framework.
The easiest way (aka the way using the smallest amount of code) to insert a row into a database table using Zend_Db is:
$data = array(
'created_on' => '2007-03-22',
'bug_description' => 'Something wrong',
'bug_status' => 'NEW'
);
$db->insert('bugs', $data);
The above code will insert a new row into the bugs table whereas $db is the Zend_Db_Adapter_Abstract-subclass you created with Zend_Db::factory(). Please see Writing Changes to the Database in the Zend Framework manual for more details and the whole spectrum of features Zend_Db provides.
For the sake of completeness, the above code will issue a query to the database similar to:
INSERT INTO bugs (created_on, bug_description, bug_status)
VALUES ('2007-03-22', 'Something wrong', 'NEW')
The next step would be a more sophisticated approach using Zend_Db_Table.
EDIT:
Given that you have a Zend_Form ($form) with the appropriate fields created_on, bug_description and bug_status and provided that you have the right filters and validators in place, adding a new row with values given in the form is as easy as
if ($form->isValid($_POST)) {
$db->insert('bugs', $form->getValues());
}
Storing a custom object is also very easy:
// $bug is your custom object representing a bug
$db->insert('bugs', array(
'created_on' => $bug->getCreatedOn(),
'bug_description' => $bug->getDescription(),
'bug_status' => $bug->getStatus()
));
Instantiate any object that you need and serialize it. Once serialized, you can store it or transmit it to pretty much any medium. Is this what you are referring to?