query-builder

WhereRaw Laravel with variable

混江龙づ霸主 提交于 2019-12-24 13:28:44
问题 I'm trying to do this query but I got an error (Malformed UTF-8 characters, possibly incorrectly encoded): DB::table('my_table')->select(DB::raw("id")) ->whereRaw('UPPER(name)','=', $upper_name) ->pluck('id')->first(); I'm trying to add the UPPER sql function to the query. With direct sql, the query should be: select * from my_table where UPPER(name) = 'HELLO' Where $upper_name = HELLO. 回答1: Simpliest Way to do that. Hope will help you DB::table('my_table')->select('id') ->where(DB::raw(

Doctrine left join with priority on language field with querybuilder

偶尔善良 提交于 2019-12-24 11:27:44
问题 I'm using the query below: use Doctrine\ORM\Query\Expr\Join; $query = $this->createQueryBuilder('ad') ->select('ad.id, ad.title, ad.year, ad.hours, ad.status') ->addSelect('rem.remark') ->leftJoin('ad.remark', 'rem', Join::WITH, "rem.language = 'NL'") ->getQuery() ->getResult(); This query is working fine and returns the remark of a ad in the Dutch language. The ad has a one-to-many relation with its remark. Only I also have ads that have for example an English remark and not a Dutch one. The

Best practices with current date in doctrine/php

爷,独闯天下 提交于 2019-12-24 11:22:19
问题 i had to retrieve datas with doctrine based on current date , i wanted to know what was the best practices about it. Should i : Pass an DateTime object representing current time as parameter of my function so i could test easily my function Instantiate an DateTime object in the setParameter() of my QueryBuilder Or just use CURRENT_TIMESTAMP() of mysql in my query builder I'm a bit lost with those choices and why should i or not choose an option. 回答1: If you're using Doctrine, then the last

Yii2 How to translate SUM SQL function to Query Builder?

这一生的挚爱 提交于 2019-12-24 09:26:03
问题 I have this simple SQL query: SELECT product_name, SUM (product_amount) FROM orders GROUP BY product_name; It will show a list with product names and their amounts. Like this example: I want to translate it to Yii2 Query Builder. I don't know how to use the SUM function. I tried this but it didn't work: Orders::find() ->select( [ Orders::tableName() . ".product_name", (new \yii\db\Query())->sum(Orders::tableName() . ".product_amount") ] ) ->groupBy( [ Orders::tableName() . '.product_name',

Laravel - find offset of record in mysql results

一曲冷凌霜 提交于 2019-12-24 08:48:32
问题 I have a MySQL table of records with several fields. These records are shown and updated live in the browser. They are displayed in an order choosen by the user, with optional filters also choosen by the user. Sometimes a change is made to one of the records, and it may affect the order for a given user. In order to position the message correctly in the list, I need to find where its new offset falls after the change to the record. Basically, I need to get the "id" for the record that now

Doctrine - query with date range

徘徊边缘 提交于 2019-12-24 06:52:04
问题 I wrote a query that I can call within my form to select date range and to return all database data in that range. The api call works fine but when I set date parameters it returns an empty result. $date = new \Datetime(); $result = $this->getMyRepository() ->createQueryBuilder('a') ->select('a') ->where('a.date >= :from') ->andWhere('a.date <= :to') ->setParameter('from', $date->format('Y-m-d H:i:s')) ->setParameter('to', $date->format('Y-m-d H:i:s')) ->orderBy('a.id') ->getQuery() -

Case insensitive search in CQ5 using querybuilder

一世执手 提交于 2019-12-24 03:07:05
问题 Please suggest on how to implement case insensitive search using querybuilder in CQ5. My code is as below ... paramMap.put("1_property", searchType); paramMap.put("1_property.value", "%" + searchString + "%"); paramMap.put("1_property.operation", "like"); paramMap.put("2_property", "documentId"); paramMap.put("2_property.operation", "exists"); paramMap.put("3_orderby.sort", "asc"); paramMap.put("p.limit", "0"); searchType is the node property searchString is the string that needs to be

getting three records in descending order of each category using codeigniter

烈酒焚心 提交于 2019-12-24 00:58:06
问题 I've two categories and I want to fetch three records of each category later I found this link UNION query with codeigniter's active record pattern after this I change my DB_Active_rec file and add this code also var $unions = array(); public function union_push($table = '') { if ($table != '') { $this->_track_aliases($table); $this->from($table); } $sql = $this->_compile_select(); array_push($this->unions, $sql); $this->_reset_select(); } public function union_flush() { $this->unions = array

“This value is not valid” when using “query_builder” on “entity” buildForm on symfony2.1

老子叫甜甜 提交于 2019-12-23 20:08:47
问题 Here is my problem. I use the buildForm method on symfony 2.1 in order to build my form. With the following code everything works just fine : $builder->add('combat','entity',array( class' => 'KarateCompetitionBundle:CompetitionCombat', 'empty_value' => 'Sélectionner un combat')); But I want to filter and display only some Combat . That's why I have to use the query_builder option. When i do that i get the This value is not valid error message. Here is the code : $builder->add('combat','entity

Laravel 5 SQLSTATE[42S22]: Column not found

三世轮回 提交于 2019-12-23 14:51:25
问题 I am doing some joins and trying to get the data. My query builder is: $datasource = DB::table('vehicles')->join('brands', 'vehicles.brand_id', '=', 'brands.id')->join('sections', 'vehicles.section_id', '=', 'sections.id')->select('vehicles.*, vehicles.id AS vid'); But i am getting this error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'vehicles.model,' in 'field list' (SQL: select vehicles . model, as AS from vehicles inner join brands on vehicles . brand_id = brands . id inner