PHP CodeIgniter Framework - Coming Soon for CUBRID Users

    The title already says it all. But I will talk in more detail about the beginning of the development and interaction of CUBRID with CodeIgniter. Also here you will learn about the differences between CUBRID and MySQL in terms of application development and adaptation.

    At the beginning of this month, I decided to work on the CUBRID driver for CI, the popular PHP framework used by so many Web developers. One of the web services in our company wants to use CI at home with CUBRID. Fortunately, this framework has an intuitive structure, which allowed me to quickly find the classes that I need to inherit and implement for CUBRID.

    I found all other supported DBMS drivers in the directory / system / database / drivers. Since CUBRID supports over 90% of MySQL SQL syntax, there was no need to start from scratch. I started working on a ready-made MySQL driver for CI. The next day I already had a working CUBRID driver code. A couple of days later, I conducted tests (unfortunately, as one of the CodeIgniter developers said, they still do not have unit tests that would cover the whole framework, including database drivers, so I had to write my own tests). As soon as the driver passed all the tests, I contacted their developers and sent pull requests to the main branch and the branch for development.

    Below I will describe which parts of the code I changed in the MySQL driver so that it stably works for CUBRID. I hope these entries will be useful to those who plan to include support for the CUBRID DBMS in their Web applications.

    1. The name of the database at the time of the connection
      Unlike MySQL, the connection in CUBRID is made directly with the database, i.e. The DSN should contain information about the database you are about to connect to. This method eliminates the need to "choose the base" after the connection. In principle, Oracle also works.
      $conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password);
    2. Broker Port
      By default, 33000 is a Broker port. If necessary, this value can be changed in the parameters of the Broker .
    3. Auto commit
      By default, auto_commit in the CUBRID is disabled (OFF). This means that developers need to commit every transaction. Thus, users can process queries in the so-called dry mode , when they can receive query results without changes to the database. Useful during development. By putting the site in real mode, you can change the value of auto_commit to ON in the CI database.php configuration file , as indicated below, or directly in the broker settings.
      $db['default']['hostname'] = 'localhost';
      $db['default']['port'] = '33000';
      $db['default']['username'] = 'dba';
      $db['default']['password'] = 'ci_pass';
      $db['default']['database'] = 'ci_demo';
      $db['default']['auto_commit'] = TRUE;
      $db['default']['dbdriver'] = 'cubrid';
      $db['default']['dbprefix'] = 'tbl_';

    4. Quoting column names
      Sometimes you need to create a column with a name that is already reserved by the DBMS itself as a keyword. In MySQL, for example, such identifiers (names of tables / columns / views, etc.) can be taken in left quotation marks, for example, `time`. In MSSQL, you must use square brackets ([time]). In Oracle, double quotes ("time").
      In CUBRID, you can use all three: left and double quotation marks, and square brackets. Double quotes can be used to highlight default identifiers, since the value of the ansi_quotes parameter in the CUBRID configuration file cubrid.conf is specified as no(i.e. do not use double quotes to highlight string values). If this value is changed to yes , then double quotes can be used only for string values. Thus, you can use the symbol you are used to as a frame for identifiers.
      Identity quotasString Values
      ansi_quotes = NO (default)left quotation marks`time`
      square brackets [time]
      double quotation marks “time”
      single quotes for string values: 'normal string'
      ansi_quotes = YESleft quotation marks`time`
      square brackets [time]
      single and double quotes for string values: 'normal string', "normal string"

    5. Optimization, Correction, Backup
      CUBRID does not provide the ability to manipulate these functions through SQL overgrowth. If you need to optimize, fix the database or make a backup, you must use the CUBRID Manager main administration tool .

    In addition to these differences, I did not make other changes to SQL queries, since almost all MySQL queries work in CUBRID. This shows how CUBRID is compatible with MySQL and how easy it is to make a port for applications that work with MySQL.

    With this example, I wanted to show that adapting applications, even as large as CodeIgniter, is very easy, and it takes no more than a few days for a newbie to CUBRID. Therefore, if you intend to adapt anything, do not hesitate. It does not take much time, you will see for yourself. And yes, if you need help in this matter, let us know in our forum and we will be happy to help you.

    As for the source code of the CUBRID driver, as you already think, I know that CodeIgniter recently officially passedto the GitHub service. A few days before that, I had already committed changes to their upcoming repository , which was now closed, and its code was combined with the official one.

    Immediately after switching to GitHub, one of their developers announced that CI will roll out CUBRID support already in version 2.1.0. Will wait!

    And if you do not want to wait and already want to test CI + CUBRID, you can merge the code from the develop branch of their official repo. If you are lucky enough to find some kind of bug, I will be happy to fix it immediately. You can report it on our forum, or on Twitter .

    If you have questions about installing and working with CUBRID, write in the comments. Also, if you have ideas about an application for which you can develop a CUBRID driver, write. I will be glad to talk about them.

    Also popular now: