<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" > <channel> <title>MySQL | Muharrem Tığdemir</title> <atom:link href="/category/mysql/feed/" rel="self" type="application/rss+xml" /> <link></link> <description>Carpe Diem!!</description> <lastBuildDate>Sat, 05 Dec 2015 17:16:02 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod> hourly </sy:updatePeriod> <sy:updateFrequency> 1 </sy:updateFrequency> <generator>https://wordpress.org/?v=6.2.2</generator> <site xmlns="com-wordpress:feed-additions:1">120145533</site> <item> <title>Mysql General Error 1364 Field Doesn’t Have Default Value</title> <link>/mysql-general-error-1364-field-doesnt-have-default-value/</link> <comments>/mysql-general-error-1364-field-doesnt-have-default-value/#comments</comments> <dc:creator><![CDATA[Muharrem Tığdemir]]></dc:creator> <pubDate>Sat, 05 Dec 2015 17:16:02 +0000</pubDate> <category><![CDATA[Laravel]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[error]]></category> <category><![CDATA[homestead]]></category> <category><![CDATA[laravel]]></category> <category><![CDATA[mysql]]></category> <guid isPermaLink="false">https://muharremtigdemir.com/?p=630</guid> <description><![CDATA[<p>Hi All, Since I’ve updated my homestead to 0.3.0 and mysql version is upgrade to 5.7.4. From that moment, my old projects has been started to throw problems which is Mysql General Error 1364 Field doesn’t have default value. Even migrations was not working, there has to be a problem. After my first research I’ve […]</p> <p>The post <a href="/mysql-general-error-1364-field-doesnt-have-default-value/">Mysql General Error 1364 Field Doesn’t Have Default Value</a> first appeared on <a href="">Muharrem Tığdemir</a>.</p>]]></description> <content:encoded><![CDATA[<p>Hi All,</p> <p>Since I’ve updated my homestead to 0.3.0 and <a href="http://3.125.49.171/category/mysql/">mysql</a> version is upgrade to 5.7.4. From that moment, my old projects has been started to throw problems which is <strong>Mysql General Error 1364 Field doesn’t have default value</strong>.</p> <p>Even migrations was not working, there has to be a problem. After my first research I’ve found a solution for Php <a href="http://3.125.49.171/category/laravel/">Laravel</a> Projects there is a “strict” parameter for mysql connection, when I set it true migrations worked well.. But, in some cases, I let the mysql to set default value such as integer fields are sets to ‘0’ and varchar fields are empty strings etc.. I need to use default values as before..</p> <p><span id="more-630"></span></p> <p>Finally, I solved my problem it’s all about <a href="http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict">SQL Mode Strict</a></p> <pre class="lang:mysql decode:true" title="Sql Mode">select @@sql_mode; </pre> <p>If the result includes <strong>STRICT_TRANS_TABLES</strong> parameters Mysql engine expect default parameters for field, otherwise you have to set that.</p> <p>Open terminal at the below command or find your my.ini/my.cnf file</p> <pre class="lang:sh decode:true">sudo nano /etc/mysql/my.cnf</pre> <p>Add at the below line after [mysqld]</p> <pre class="lang:mysql decode:true">sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"</pre> <p>Try again..</p> <p>Muharrem Tığdemir</p><p>The post <a href="/mysql-general-error-1364-field-doesnt-have-default-value/">Mysql General Error 1364 Field Doesn’t Have Default Value</a> first appeared on <a href="">Muharrem Tığdemir</a>.</p>]]></content:encoded> <wfw:commentRss>/mysql-general-error-1364-field-doesnt-have-default-value/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <post-id xmlns="com-wordpress:feed-additions:1">630</post-id> </item> <item> <title>Laravel Eloquent Model Events</title> <link>/laravel-eloquent-model-events/</link> <comments>/laravel-eloquent-model-events/#respond</comments> <dc:creator><![CDATA[Muharrem Tığdemir]]></dc:creator> <pubDate>Sun, 01 Feb 2015 16:04:19 +0000</pubDate> <category><![CDATA[Laravel]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[eloquent model events]]></category> <category><![CDATA[eloquent model trigger]]></category> <category><![CDATA[laravel model events]]></category> <category><![CDATA[laravel model trigger]]></category> <guid isPermaLink="false">https://muharremtigdemir.com/?p=537</guid> <description><![CDATA[<p>Hi All , In this post , I’ll talk about Eloquent Model Events. Looks Like Database Trigger Isn’t it? When I read the documentation , I said “Mysql already doing this so..”. Personally, still I prefer to use Mysql Triggers for database operations. It’s more faster and guaranteed. But day by day NoSQL solutions or Hybrid database solutions […]</p> <p>The post <a href="/laravel-eloquent-model-events/">Laravel Eloquent Model Events</a> first appeared on <a href="">Muharrem Tığdemir</a>.</p>]]></description> <content:encoded><![CDATA[<p>Hi All ,</p> <p style="padding-left: 30px;">In this post , I’ll talk about <em>Eloquent Model Events</em>.</p> <h3>Looks Like Database Trigger Isn’t it?</h3> <p style="padding-left: 30px;">When I read the documentation , I said “Mysql already doing this so..”. Personally, still I prefer to use Mysql Triggers for database operations. It’s more faster and guaranteed. But day by day NoSQL solutions or Hybrid database solutions like using MongoDB and Mysql together becoming as a popular solutions. Also each NoSQL database is different, but MongoDB doesn’t support actually stored procedures or triggers. In that case , we need to handle this kind of situations.</p> <p style="padding-left: 30px;">If you are interested in MySQL-NoSQL Hybrid Solution with Laravel. You can check <a href="https://github.com/jenssegers/laravel-mongodb#mysql-relations" target="_blank">this </a>package by <a title="Jenssegers" href="https://github.com/jenssegers" target="_blank">Jessenger</a>.</p> <h3>For More</h3> <p style="padding-left: 30px;"><a title="Laravel" href="http://3.125.49.171/category/laravel/" target="_blank">Laravel </a>site has a simple usage example for <strong>Eloquent Model Events</strong> for “Validation”. In real projects , we have to validate every input , when model “updating” and “creating” its very important. So, Model Events is amazingly useful for this job. You can check the JeffreyWay Model Validation package from <a title="Laravel Model Validation" href="https://github.com/JeffreyWay/Laravel-Model-Validation" target="_blank">github</a>. This package supports model based validation rules.</p> <p style="padding-left: 30px;">Generaly, we need to delete photos , avatars , attachments from FTP too or Logging Model actions<strong>. </strong> We can add more usages examples depends on situation. Let’s see abilities of Model Events.</p> <p style="padding-left: 30px;"><span id="more-537"></span></p> <h3>Event Types</h3> <ul style="list-style-type: circle;"> <li><code>Creating<span style="font-size: 16px; line-height: 24px;"> </span></code></li> <li><code>Created</code></li> <li><code>Updating</code></li> <li><code>Updated</code></li> <li><code>Saving</code></li> <li><code>Saved</code></li> <li><code>Deleting<span style="font-size: 16px; line-height: 24px;"> </span></code></li> <li><code>Deleted<span style="font-size: 16px; line-height: 24px;"> </span></code></li> <li><code>Restoring</code></li> <li><code>Restored</code></li> </ul> <h3>“Talk is cheap Show me the code”..</h3> <p>Let’s make a little scenario. I have “Users” , “Photos” and “Comments” with following Relations.</p> <ul> <li style="padding-left: 30px;">User Has Many Photo</li> <li style="padding-left: 30px;">User Has Many Comment</li> <li style="padding-left: 30px;">Photo Has Many Comment</li> </ul> <p><strong>Example 1 : </strong> I want to delete file of Photo from FTP when Model Deleted.</p> <pre class="lang:php decode:true"> protected static function boot() { parent::boot(); static::deleted(function(Photo $photo) { // Get the Real Photo Path $filename = public_path('photos/'.$photo->url); if (File::exists($filename)) { File::delete($filename); } else { return false; } }); } </pre> <p> </p> <p><strong>Example 2 : </strong>Let’s say I need to Log all update actions or versioning from Comment Model.</p> <pre class="lang:php decode:true" title="Updated Model Logging">protected static function boot() { parent::boot(); static::updated(function(Comment $comment){ Log::info($comment->user_id." updated at ".$comment->updated_at); //local.INFO: 1 updated at time }); }</pre> <p><em>You can check the storage/laravel.log file.</em></p> <p> </p> <p><strong>Example 3 :</strong> I want to update Total Photo Comment when new Comment created.</p> <p><span style="color: #00ffff;"><span style="color: #000000;"><strong>NOT</strong><strong>E</strong></span><em><span style="color: #000000;"><strong> :</strong></span><span style="color: #ff0000;"> This can be do it by MySQL trigger.</span></em></span></p> <pre class="lang:php decode:true" title="Comment Boot"> protected static function boot() { parent::boot(); static::created(function(Comment $comment) { //Created Comment echo "Created Comment : " . $comment; //Total Comment Belongs To Photo $total_comment = Photo::find($comment->photo_id)->comments()->count(); //Print Total Photo echo "</br>Total Comment : " . $total_comment; //Update total Comment of Photo echo "<br> Update Status : " . Photo::where('id', $comment->photo_id) ->update(array('total_comment' => $total_comment)); }); }</pre> <p> </p> <p>Most useful things in this example Depency Injection. When I call the static::created function. It’s comming with Created “Comment Model”. Now, i’m able to reach functions which is belongs to Comment Model like “photos()”</p> <p>As a Result Following SQL executed.</p> <pre class="lang:mysql decode:true">insert into `comments` (`text`, `user_id`, `photo_id`, `updated_at`, `created_at`) values ('Test Comment', '1', '9', '2015-02-01 11:32:12', '2015-02-01 11:32:12') select count(*) as aggregate from `comments` where `comments`.`photo_id` = '9' update `photos` set `total_comment` = '26', `updated_at` = '2015-02-01 11:32:12' where `id` = '9'</pre> <p> </p> <p>Happy Coding..</p> <p>Muharrem Tığdemir</p> <p> </p><p>The post <a href="/laravel-eloquent-model-events/">Laravel Eloquent Model Events</a> first appeared on <a href="">Muharrem Tığdemir</a>.</p>]]></content:encoded> <wfw:commentRss>/laravel-eloquent-model-events/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <post-id xmlns="com-wordpress:feed-additions:1">537</post-id> </item> <item> <title>MySQL Limitli Sorgu Toplam Satır Sayısı</title> <link>/mysql-limit-sorgu-toplam-satir-sayisi/</link> <comments>/mysql-limit-sorgu-toplam-satir-sayisi/#respond</comments> <dc:creator><![CDATA[Muharrem Tığdemir]]></dc:creator> <pubDate>Fri, 27 Dec 2013 14:22:53 +0000</pubDate> <category><![CDATA[MySQL]]></category> <category><![CDATA[found_rows]]></category> <category><![CDATA[limitsiz]]></category> <category><![CDATA[limitsiz sorgu sayı]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[sql]]></category> <category><![CDATA[SQL_CALC_FOUND_ROWS]]></category> <category><![CDATA[toplam]]></category> <guid isPermaLink="false">https://muharremtigdemir.com/?p=209</guid> <description><![CDATA[<p>Merhaba Arkadaşlar , Web uygulamalarımızın vazgeçilmezi olan Ajax uzun database sorgularında bizi çok işten kurtarıyor. Ama sayfalama yaparken , datatables kullanırken veya search gibi karmaşık sorgularımızın gerçek uzunluğuna ihtiyacımız oluyor. MySQL’in bunun için çözümü şu şekilde SELECT SQL_CALC_FOUND_ROWS user_id , username FROM users LIMIT 10 Bu sorgudan sonra; SELECT FOUND_ROWS() AS `Count` sorgusunu çalıştırırsanız , […]</p> <p>The post <a href="/mysql-limit-sorgu-toplam-satir-sayisi/">MySQL Limitli Sorgu Toplam Satır Sayısı</a> first appeared on <a href="">Muharrem Tığdemir</a>.</p>]]></description> <content:encoded><![CDATA[<p>Merhaba Arkadaşlar ,</p> <p>Web uygulamalarımızın vazgeçilmezi olan Ajax uzun database sorgularında bizi çok işten kurtarıyor. Ama sayfalama yaparken , datatables kullanırken veya search gibi karmaşık sorgularımızın gerçek uzunluğuna ihtiyacımız oluyor. MySQL’in bunun için çözümü şu şekilde</p> <pre class="lang:mysql decode:true">SELECT SQL_CALC_FOUND_ROWS user_id , username FROM users LIMIT 10</pre> <p>Bu sorgudan sonra;</p> <pre class="lang:mysql decode:true">SELECT FOUND_ROWS() AS `Count`</pre> <p>sorgusunu çalıştırırsanız , sorgunun limitsiz sonucuna ulaşabiliyorsunuz. Tabiki önemli nokta asıl sorgunuzda SELECT ‘den sonra “SQL_CALC_FOUND_ROWS” kodunu eklemelisiniz.</p> <p><span id="more-209"></span></p> <p>Ayrıntılı bilgi için aşağıdaki linki inceleyebilirsiniz.</p> <p><a href="http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows">http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows</a></p> <p> </p> <p>Muharrem Tığdemir</p><p>The post <a href="/mysql-limit-sorgu-toplam-satir-sayisi/">MySQL Limitli Sorgu Toplam Satır Sayısı</a> first appeared on <a href="">Muharrem Tığdemir</a>.</p>]]></content:encoded> <wfw:commentRss>/mysql-limit-sorgu-toplam-satir-sayisi/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <post-id xmlns="com-wordpress:feed-additions:1">209</post-id> </item> </channel> </rss>