Claudiu Persoiu

Blog-ul lui Claudiu Persoiu


Archive for the ‘MySQL’ tag

Oracle to buy Sun – a new chapter

without comments

It seems like Oracle received the unconditional approval from EU to by Sun according to Yahoo! News.

About and year and a half ago I was considering the MySQL Certified Developer exam. Now I’ve become Sun MySQL Certified Developer and it seems like I’ll even become Oracle MySQL Certified Developer. And all of this with no extra charge! 🙂

The good part is that we’ll become Oracle developers even if we don’t want or plan to (ok, is not exactly Oracle, but one of there products).

Written by Claudiu Persoiu

26 January 2010 at 9:57 PM

Posted in Diverse,MySQL

Tagged with , ,

Another year has passed and PHP 6 is still not here…

without comments

Another year has passed and PHP 6 is still not here…

But that’s not exactly news, is the 4-th year when this long awaited version is not released. Not for nothing is called the most awaited version.

But overall it was a good year for the community, even though we still don’t have native Unicode in a stable version now we have all other awaited features in PHP 5.3, which will probably need another few years to become used on a large scale.

Even though everyone was expecting last year for Oracle to enter in full force on medium and small database market by purchasing Sun, enlarging it’s already well established  portfolio on the enterprise market. It seems that it was not to be, CE is still analyzing the deal.

However MySQL is not what it used to be 5-6 years ago, when nobody dared to use it for enterprise products. This days MySQL is a product ready to be used in both small and large products that require a lot of scalability.

But back to the year that just ended, it was a full year, even with this economic crises.

Written by Claudiu Persoiu

13 January 2010 at 8:30 AM

Posted in Diverse,MySQL,PHP

Tagged with , ,

Bad code and frameworks

without comments

Why there is so much talking about “bad code” or “bad practices”? Because they are important!
Lately I had an unpleasant experience with uncommented code, bad design, bad implemented oop, unoptimized and badly designed  databases.

Comments

Is a great mystery to me how it’s possible that every book and tutorial (not just PHP) to say that comments are not optional but MANDATORY and most often there entirely missing. Zend Studio has a very simple and efficient auto-complete system, you just have to tap “/**” and press enter, and then just complete the text. Netbeans has a similar system, just as easy.

And still, I’ve came over thousands of lines of code with almost no comments at all. The outcome? Hours and hours wasted trying to follow the logic!

Why is this happening? First reason: is boring, a developer want’s to write code not stories, usually seems like wasted time. The second reason: everything seems very logic when it’s written, if it’s so logic and fluent why waste time with stories? Because time passes, projects change, and with time is inevitable that the logic will be forgotten. Or another reason, new employees will come, in companies developers come and go, and the new guy can’t follow the logic with the same ease, in fact it is almost impossible to follow.  Even the author of the code can’t follow the steps after a long period of time, sometimes the author was me.

In my opinion this should be a rule of thumb for every company, no class/method/property should be left uncommented. Time spend now on commentaries is time gain later when will be done debugging,optimization etc.

Bad design

I’ve encounter a question on an on-line  “mini interview”: “do you see the importance of architect analysis before writing code?”, I’m sorry if the I didn’t get the exact question. The first time I’ve seen that question I had an “deja-vu” moment, a lot of the time I’ve started writing code only to realize that was the wrong approach.

A lot of the times, the issue is solved (apparently) with time and experience. Basically, if you get a beginner to write code, most likely he will have some bad approaches before getting a good one, and this is not abnormal, that’s why I think a beginner should be guided before he will begin to write code, and the resulting code to have a suggested logic by a “mentor”.

On the other extreme there are “software architects” which using UML they describe the logic and the structures using diagrams. When diagrams exist is much easier to follow the entire process and structure of the app. An experienced architect will be able to see the possible issues that may appear before beginning to write code, and when code is starting to be written everyone knows just what they have to do.

OOP is probably the most affected by poor design. Lately I’ve seen a lot of classes which had no internal structure, there ware just simple wrappers for SQL queries. That’s not OOP!

OOP is about abstracting elements in classes and objects. For instance the keyboard is a class which has keys (a child class) with various properties (letters, key code, position), some LEDs (another child class) etc. The way there organize in the database is not necessary in a tight relation with the resulting objects, as it may seem.

If your using OOP and what you are reading now sounds weird, try drawing on a piece of paper a diagram of the objects in your app and the references between them. If you can’t, it means that your approach to the OOP is wrong (or you just don’t know to draw a diagram 🙂 )!

We all make mistakes when it comes to OOP, but that’s not an excuse not to correct them, and to try to make architecture before code.

A bad app design may have very important financial implications. Time is money, and if an app has poor design, is not correctly structured, the debugging time is big, changes and enhancements require a lot of time, is a lot of code redundancy, etc. , then you can be sure your losing money.

A tool that I sometimes use is Violet UML Editor, is not a true UML editor like Rational Rose for instance, but rather an open-source toy. With Violet you can only build visual diagrams, but they can be useful to visually structure an app.

Databases

Why are PHP developers avoiding to truly learn MySQL? Sounds strange? Is very true though. Modifying PHP code is usually not very difficult (I mean the practical rewriting the code), but a bad database design is most of the times more difficult to change because is the risk of losing data.

A few weeks ago I’ve made a diagram of the database using MySQL Dump and MySQL Workbench. I was quite surprise to see tables which didn’t have relation keys with the tables from which the information came from (I don’t mean settings tables or other tables which logically don’t have a relation with the other tables), then the data source was completely lost.

Another classic problem with beginners is that when they have a relation table between two other tables, like categories and products for instance, the primary key is on a field like “id” which has no relevance. A primary key can be set on multiple fields, like for the previous example “id_category, id_product” not “id”, this way you ensure the uniqueness of a product in a category using the primary key restriction.

Another thing that is usually avoided are the indexes. In a previous blog post I was shortly explaining them, insufficient even though there important. An index can significantly reduce the search time in a table, from tenths of a second to a thousandths of a second. A badly optimized app from this point of view can have a significant bigger response time then normal.

Frameworks

To quote a classical phrase in the PHP community:

All frameworks suck.

and Laura Thomson had some strong reasons to back this up.

Somebody was saying last week that the reason for bad code is actually PHP and it’s loose typing. Let’s be honest, if we take in consideration a language like C++ there are a lot more issues that can arise. I remember in faculty how bad my C++ code was, and  the problem wasn’t the language but rather my skills at that time. PHP allows approaches from OOP to spaghetti code (OOP, procedural, closures, labels). The fact that many developers chose bad approaches is not a language problem, there is the same approach issue with a language like C++, or in fact with any programming language out there.

Why are less design problems in Ruby on Rails for instance? Because is a framework! I’ve never heard of anybody doing web developing just using Ruby (there are developers out there, especially for desktop apps, but that’s another story), of course there are less issues when using a framework. The same way PHP issues can be reduced using an popular framework.

There are tens or even hundreds of open-source PHP frameworks. Of this there are a few really popular, like Zend Framework, CakePHP, Symfony, Solar, CodeIgniter etc. An great advantage when using a popular framework is that is easy to find professionals. Another big advantage is that you have a well tested and documented code base, thing that is very hard to achieve in a small company.

Or even if your using an in-house framework I thing is a good idea to adopt a structure of an popular framework to reduce the learning curve for new developers.

Using an popular open-source framework usually you reduce the working time and the time to develop nu features because usually there included in the framework, so economical advantages bay arise (money), a better structure and last but not least happier developers (which I’m not at this time).

Concluding:

  • set some rules for the code standards, don’t forget to add the comments to the list,
  • make sure the app design is according to a plan that allows for scalability and minimal code redundancy,
  • make sure the database is well structured and optimized,
  • consider an open-source popular framework over building an internal one.

Using this simple rules will save resources, time, and probably developers will be more happy with there result.

Written by Claudiu Persoiu

4 October 2009 at 2:07 PM

Posted in MySQL,PHP

Tagged with , ,

MySQL and Unicode using UTF-8

without comments

Along with globalization, the old ASCII code is no longer suitable.  Consider that one day you have to develop a project in German, Russian or even Japanese, you could adapt the charset for each of these languages or you could simply develop using Unicode.

To use Unicode with MySQL UTF-8 can be used.

You must note that UTF-8 characters are variable in length and they are ASCII compatible. In ASCII 1 char = 1B, in UTF-8 1 char can be between 1 and 4 B.

UTF-8 charset and collation on the server

Character type in MySQL is dictated by charset.

To check if UTF-8 in installed on the server:

SHOW CHARSET LIKE 'utf8';

or with information_schema

SELECT * FROM `CHARACTER_SETS` WHERE CHARACTER_SET_NAME = 'utf8';

If the charset was found then we can continue.

Another element that appears with charset is collation, which it’s used for comparing strings at ordering.

To see what collations are available on the server:

SHOW COLLATION WHERE CHARSET = 'utf8';

or with information_schema

SELECT * FROM `COLLATIONS` WHERE CHARACTER_SET_NAME = 'utf8';

Collation are usually by language, for comparing strings with or without diacritics for example, or “bin” can be used with orders strings in binary mode,  ie “A” is greater than “a” for example.

If no collation is specified, then the default one will be used.

UTF-8 and data bases

When creating a database you can specify the default charset to be used with all new tables for which there isn’t any charset specified.

For example:

CREATE DATABASE db_name CHARACTER SET utf8 COLLATE utf8_romanian_ci;

Or for modifying the default charset for a data base which already exists:

ALTER DATABASE db_name CHARACTER SET utf8 COLLATE utf8_romanian_ci;

UTF-8, tables and columns

For modifying tables which already exist ALTER TABLE must be used is used.

A table can have a default charset and collation, and each column can have it’s own charset and collation.

For more information about the table:

SHOW CREATE TABLE tab;

To set a charset for an existing table:

ALTER TABLE tab CHARSET = utf8 COLLATE = utf8_romanian_ci;

For modifying the charset of a VARCHAR(200) column is used:

ALTER TABLE tab MODIFY c1 VARCHAR(200) CHARSET utf8 COLLATE utf8_romanian_ci;

String size

A “problem” that may arise is related to the size of the character, it’s size can be between 1 and 4B.  That is why for measuring a string column (like varchar) you must use CHAR_LENGTH(str) instead of LENGTH().

A short exemple:

SET @var = 'aşadar';
SELECT CHAR_LENGTH(@var) AS 'Char', LENGTH(@var) AS 'Length';

// The output is: Char = 6 and Length = 7 because ş is 2B

Written by Claudiu Persoiu

10 August 2009 at 1:40 PM

Posted in MySQL

Tagged with , , ,

MySQL Certified Developer – last episode

without comments

After taking MySQL Certified Developer exam a few weeks ago,  as telling in a previous blog, the moment has arrived. Is a little crooked because it was forced in the mail box, but my diploma has arrived! Surprisingly it took only two weeks, compared to that of the Zend, which took almost 8.

My name was published on the site in a few days, but I was unableto access my account until after I received the diploma. What is strange is that in the envelope is not the password of the account, but the instructions to receive it.

Beside the diploma, in the envelope there are instructions for using the logo and account, and besides that a card with my name and certification, which I do not understand what is for.

And another weird thing is that, the diploma is signed by Micheal “Monty” Widenius and Marten Mickos who no longer work at Sun MySQL. Obviously I do not know how true are the signatures, but at least Ulf Sandberg (VP Service MySQL AB) signature is real.

But diploma looks very good, and make a good pair with the Zend one. Now I hope it will be useful.

Written by Claudiu Persoiu

30 July 2009 at 9:13 PM

Posted in MySQL

Tagged with , ,

Software adoption rate and web development

with 2 comments

How does the rate of adoption of new software products and/or version influences the software development for Web and client-server type products?
From the perspective of a web developer, we are restricted by the servers for which we develop and our client’s browsers. Compromise often go very far for the sake of meeting a more broader market.

PHP

Currently stable version of PHP is 5.3.0, but using this version in production would be a childish decision. The version has been out for a little while and the probability to find this version on the hosting servers is very slim.

Of course, a more appropriate version is 5.2.10.  And yet, if version 5 was released almost 5 years now, why a popular framework like CakePHP yet uses the advantages brought by this version? Because until recently an important part of shared hosting servers that have support for PHP, still had version 4.

How is this translated in production? If you don’t develop internal products, or on your own servers, or servers which you can control, you should be aware that your product should be compatible with older PHP versions, and the new features of the language should not be used in production.
Ridiculous and sad but true.
PHP 5.3 brings quite a lot of new features,  but until these features can be used in production few years will have to pass. And until they get in frameworks probably even more (ie namespaces are useful in frameworks).

MySQL

Current stable version is 5.1.36. 5.x version, released in2005 brought many new features, some of them are: stored routines (functions and procedures), triggers, views, cursors, information schema, etc.

Stored routines is probably one of the biggest changes. They are probably most known from Oracle PL/SQL, although MySQL has implemented from the ANSI SQL 2003standard.

Because MySQL 5.0 was in beta for a long time, the rate of adoption is very low. Again, after almost 4 years since the version was released, and it is not yet sufficiently widespred.

Conclusion, simply put it is not recommended the use of the new features if you can not control the version on the server.

Browsers and JavaScrip

The browser problem affects both developers and designers.

Probably the oldest browser still used on a large enough scale is Internet Explorer 6. It was launched in 2001 and after 8 years it is still used by ~ 30% of users.

JavaScript in 2001 was still considered a scripting language infant, which was mostly used for visual effects.

After the “discovery” of AJAX in 2005 , JavaScript was reborn. JavaScript was not just a scripting language used for reduced visual effects, but was regarded as a technology of the future.

Browsers such as FireFox, Opera, Google Chrome or Safari have made progress to improve the speed of JavaScript execution. Even Internet Explorer 8 works better with JavaScript, but it is far from being as popular as version 6. And for the problem to be complete, Microsoft has a big issue with keeping the compatibility between their products.

The reason for this problem in adoption of new versions of Internet Explorer is the operating system. The most popular operating system is Microsoft Windows XP and it has pre-installed Internet Explorer 6. Given that Windows Vista had a fairly low adoption rate because of the initial bugs, drivers issues, resource consumption, and other problems, meant that Windows XP was still very popular. Of course not everyone using Windows XP use IE 6, many have updated or simply use another browser. But still many of them are using the browser that is default.

Speaking of this, Windows 7 will be distributed in Europe without IE installed. I’m very curious how will this influence the browsers market.

Lately “smart phones” and PDA devices have become increasingly popular. A lot of people use them to navigate on the Internet. So after the issues related to browsers on PCs, now there is a hole new set of issues on mobile device browsers.

For instance, my phone came with two browsers: Internet Explorer and Opera. Internet Explorer Mobile is terrible, so I’m using Opera which does a good job.

The problem is that many PDA / smart phone devices with Windows Mobile OS only have Internet Explorer in standard, and the previous problem returns.
When it comes to the famous Apple iPhone, Safari browser is used (and I believe that you can’t install another browser, but I’m not sure if that is true any longer).
So when you create an interface or a JavaScript application, you must take into account several aspects such as:

  • device(eg PC, PDA, smart phone etc.)
  • operating system (eg Windows, Linux, Mac, Symbian etc.)
  • browsers and there versions (eg Internet Explorer 6,7,8; FireFox, Safari, Opera etc.)
  • HTML 5 is almost here, but when it comes to browsers, I wonder when will we be able to use it on a large scale, given that the market is currently dominated by IE 6 and 7.

    I give it about 5 years…

    Written by Claudiu Persoiu

    15 July 2009 at 9:55 PM

    Examen MySQL Certified Developer

    with 12 comments

    Sau mai nou Sun MySQL Certified Developer.

    Ma batea gandul de aproape un an, dar in ultimele luni m-am decis sa fac si pasul asta. Si cum eram usor lipsit de motivatie, pe site-ul MySQL este un anunt ca pe data de 31 Iulie examenulul nu se va mai da in centrele PersonVUE. Asta a fost toata motivatia de care aveam nevoie.  M-am inarmat cu cartea si am pornit la treaba.

    Cartea (MySQL 5.0 Certification Study Guide) nu mai este in totalitate de actualitate, fiind scrisa pentru versinea 5.0 in anul 2005. Totusi trecand peste miciile probleme cu modificarile dintre versiuni, este scrisa foarte bine, foarte explicita si cu multe exemple. Apropo, ce nu scrie in carte nu se cere.

    Cartea are doua parti, prima pentru CMDEV iar a doua pentru CMDBA. Cele doua sectiuni mai fac referire una la alta cand este cazul, dar nu este necesara parcurgerea ambelor sectiuni pentru examen.

    Dupa doua saptamani de studiu din prima parte m-am prezentat la primul examen (CMDEV I). Poate este doar parerea mea, si recunosc, am devenit comod avand in vedere ca in cea mai mare parte lucrez cu MySQL folosind phpMyAdmin, dar examenul imi pare destul de dificil. La Zend cand ai o intrebare cu raspunsuri multiple ai si numarul raspunsurilor care trebuiesc furnizate. La MySQL nu exista nici o regula in sensul asta, intradevar pot fi unul sau mai multe raspunsuri corecte.

    Un alt element de noutate, cel putin pentru mine, la final am primit si scorul, si chiar daca nu a fost aproape de limita… tot mi se pare un pic dezamagitor.

    Dupa primul examen, nu am stat mult sa sarbatoresc ca am inceput sa ma pregatesc de partea a doua.

    Unii spun ca examenul nu este bine echilibrat, iar eu cred ca au dreptate. In al doilea examen pentru certificare sunt multe elemente de care eu unul doar am auzit, sau le-am folosit cu Oracle. Motivul pentru care nu am apucat sa le folosesc pana acum este simplu: multe servere inca NU au MySQL 5.x! O alta problema este aceea ca phpMyAdmin nu avea nici un fel de suport pentru rutine stocate, triggere etc. Dar din fericire din fericire in MySQL 5.x exista Information Schema, dar desprea asta poate in alt post.

    Al doilea examen mie unul mi s-a parut ceva mai intortochiat. Daca primul l-am rezolvat intr-o ora, pe al doilea l-am rezolvat in aproape o ora jumatate (cat timpul alocat). Exemplele sunt destul de mari si trebuie interpretate cu atentie.

    Dar intr-un final am reusit!

    Din pacate treaba nu merge la fel de usor ca la Zend, acolo pana am ajuns acasa de la examen am primit si siglele (pe e-mail), termenii si conditiile de folosirea a siglelor si am putut sa-mi public profilul pe site.

    La MySQL trebuie sa primesc o hartie prin posta (ne electronica) care ar trebui sa ajunga in 4-6 saptamani. Pana atunci nu-mi ramane decat sa astept…

    Written by Claudiu Persoiu

    8 July 2009 at 11:57 PM

    Posted in MySQL

    Tagged with , , ,

    Fisiere stocate in baza de date cu PHP si MySQL

    without comments

    In continuare voi prezenta un mic tutorial despre stocarea fisierelor in baza de date.

    Cand avem nevoie de stocarea fisierelor in baza de date? Un scenariu bun este atunci cand fisierele sunt confidentiale.

    Dezavantajul principal este viteza de acces, cat timp mai este si o baza de date la mijloc asta va intarzia procesul de regasire/afisare.

    Structura bazei de date:

    CREATE TABLE IF NOT EXISTS fisiere (
      ID int(10) unsigned NOT NULL AUTO_INCREMENT,
      nume varchar(255) NOT NULL,
      tip varchar(255) NOT NULL,
      marime int(11) NOT NULL,
      fisiere longblob NOT NULL,
      timp int(11) DEFAULT NULL,
      PRIMARY KEY (`ID`)
    ) ENGINE=MyISAM

    Trebuie sa stocam tipul, marimea si continutul fisierului propriuzis. Numele este retinut mai mult pt extensie.

    Conectarea la baza de date:

    <?php
    // db.php
    mysql_connect('localhost', 'user', 'parola');
    mysql_select_db('fisiere');
    
    // am omis intentionat tag-ul de inchis pt PHP
    // ca sa am certitudinea ca nu se trimit headere

    Fisierul de upload si listare:

    In acest fisier se afla adaugare, stergerea si listarea fisierelor din baza de date

    <?php
    // legatura la baza de date
    include('db.php');
    
    // mesaj de eroare
    $errmsg = NULL;
    
    // stergerea fisierului din BD
    if(isset($_GET['del']))
    {
        $qr="DELETE FROM fisiere WHERE ID='".mysql_escape_string($_GET['del'])."'";
        if(!mysql_query($qr)) {
           $errmsg = 'Fisierul nu a putut fi sters!<br>';
        }
    }
    
    // verificam daca a fost trimis un fisier si are diminesiunea mai mare de 0
    if($_FILES['fisier']['size'] > 0) {
    
       // se citeste continutul fisierului
       $content = file_get_contents($_FILES['fisier']['tmp_name']);
    
       // se codeaza cu base64_encode pt a nu aparea probleme la caractere speciale
       //si se sparge in bucati
       $content = chunk_split(base64_encode($content));
    
       // se introduc datele in baza de date
       $qr="INSERT INTO fisiere SET
          nume   ='".mysql_escape_string($_FILES['fisier']['name'])."',
          tip    ='".mysql_escape_string($_FILES['fisier']['type'])."',
          marime ='".mysql_escape_string($_FILES['fisier']['size'])."',
          fisiere='".$content."',
          timp   ='".time()."'";
    
       // se verifica daca datele au fost inserate cu succes
       if(mysql_query($qr)) {
          // daca datele au fost stocare cu succes se face refres la pagina
          // pentru a evita cazul in care utilizatorul apasa "refresh"
          header("Location: ".$PHP_SELF."?ok=1");
          exit();
       } else {
          $errmsg = 'Eroare la upload<br>';
       }
    
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Fisiere</title>
    </head>
    
    <body>
    <?php
    if($_GET['ok']==1) echo "fisierul a fost incarcat!";
    // afisaza mesajul de eroare daca acesta exista
    if($errmsg) echo $errmsg;
    ?>
    
    <?php
    // selecteaza fisierele din BD
    $qr="SELECT * FROM fisiere ORDER BY timp";
    $rez=mysql_query($qr);
    if(mysql_num_rows($rez)>0) {
    ?>
    <table border="1">
       <tr>
          <td>ID</td>
          <td>Nume</td>
          <td>Ora</td>
          <td>Descarca</td>
          <td>sterge</td>
       </tr>
       <?php
       while($row=mysql_fetch_array($rez)) {
       ?>
       <tr>
          <td><?php echo $row["ID"]; ?></td>
          <td><?php echo $row["nume"]; ?></td>
          <td><?php echo date("d-m-Y",$row["timp"]); ?></td>
          <td><a href="descarca.php?ID=<?php echo $row["ID"]; ?>">descarca fisier</a></td>
          <td>
            <a href="<?php echo $_SERVER['PHP_SELF']; ?>?del=<?php echo $row["ID"] ?>"
                onclick="return confirm('doriti sa stergeti acest fisier?');">
              sterge
            </a>
          </td>
        </tr>
        <?php } ?>
    </table>
    <?php
    } else {
        echo "nu exista fisiere in baza de date!";
    }
    ?>
    <br />
    <br />
    <form method="post" enctype="multipart/form-data"
       action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="file" name="fisier" />
    <input type="submit" value="Incarca" />
    </form>
    </body>
    </html>

    Descarcarea fisierului:

    <?php
    include('db.php');
    
    // selectarea fisierului din BD
    $qr="SELECT * FROM fisiere WHERE ID='".mysql_escape_string($_GET['ID'])."'";
    $rez=mysql_query($qr);
    $row=mysql_fetch_array($rez);
    
    $size = $row['marime'];
    $type = $row['tip'];
    $name = $row['nume'];
    $fisiere = $row['fisiere'];
    
    // dezactivam compresia pt ca nu aparea erori la afisare
    if(ini_get('zlib.output_compression'))
    ini_set('zlib.output_compression', 'Off');
    
    // fisierul trebuie descarcat de pe server nu din cache
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); 
    
    // dimensiunea fisierului
    header("Content-length: ".$size);
    
    // tipul fisierului
    header("Content-Type: ".$type); 
    
    // optional daca dorim sa forteze download-ul
    header("Content-Type: application/force-download");
    
    // numele fisierului cu care va fi salvat pe disk
    header("Content-Disposition: attachment; filename=\"".$name."\";"); 
    
    // transfer binar pt a evita caracterele speciale
    header("Content-Transfer-Encoding: binary");
    
    // decodam continutul fisierului si il afisam
    echo base64_decode($fisiere);
    
    ?>

    Dupa cum se poate vedea serverul are destul de multe lucruri de facut pentru a afisa un simplu fisier, de asta nu este bine sa fie stocate pe disk toate fisierele, ar fi o risipa de resurse. Pe de alta parte,  fisierele private (cum ar fi cartile digitale sau melodiile) sunt clienti ideali pentru aceasta forma de stocare.

    Written by Claudiu Persoiu

    18 May 2009 at 4:00 PM

    Posted in MySQL,PHP

    Tagged with , , ,

    E mai sigur sa fi “dummy” cand vine vorba de MySQL – folositi –i-am-a-dummy

    without comments

    Da, nu e o gluma, chiar exista acest parametru, iar el este sinonim cu –safe-updates.

    Cum ii spui clientului mysql ca esti dummy?

    shell>mysql --i-am-a-dummy

    Iar pentru sinceritate, clientul mysql nu o sa te lase sa:

    • stergi sau sa modifici (DELETE, UPDATE) daca nu ai conditii puse
    • afisezi mai mult de 1000 de randuri de inregistrari
    • selecturi multiple care necesita procesarea a mai mult de 1 milion de randuri

    Uneori este mai sigur sa recunosti ca poti fi putin dummy decat sa o dovedesti…

    Written by Claudiu Persoiu

    11 May 2009 at 10:40 PM

    Posted in MySQL

    Tagged with

    MySQL intra sub umbrela Oracle

    without comments

    Da, MySQL va intra sub umbrela Oracle odata cu achizitionarea sa de catre aceasta corporatie.

    Achizitionarea nu este directa ci prin intermediul Sun (JAVA) care la randul lor au cumparat MySQL cu ceva timp in urma.

    Incepand de pe 20 aprilie 2009 e oficial, Oracle va achizitiona Sun si deci MySQL, asa cum a fost anuntat pe site-ul Sun.

    Sunt foarte curios care o sa fie rezultatul, in special ca cele doua SGBD-uri sunt populare in sectoare de piata diferite. Probabil MySQL ar putea profita de experienta Oracle, oricum probabil Oracle nu era interesat atat de interesat de tranzactia cu MySQL cat de tranzactia cu Sun.

    Daca ne gandim practic Oracle mananca “cu pofta” toate resursele care le are disponibile, pe cand MySQL este cunoscut pentru consumul redus de resurse. O sa fie foarte ciudat ca aceste opusuri sa faca parte dintr-o singura corporatie.

    Oricum, rezultatul este ca Oracle va controla majoritatea pietei de SGBD-uri prin cele doua produse de acest gen care le va dezvolta.

    Written by Claudiu Persoiu

    23 April 2009 at 9:49 PM

    Posted in Diverse,MySQL

    Tagged with , ,