CodeIgniter Forums
$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: $this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) (/showthread.php?tid=51515)

Pages: 1 2 3


$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]PaulBY[/eluser]
Hello. This funny bag has been found by me.
I have:

1) The controller:
Code:
<?php
class Test extends CI_Controller {
    public function one() {
        $this->load->database();
        $this->db->query("INSERT INTO test VALUES ('','10')");
        $this->load->view('site_before_footer');
    }
} ?>
2) The database:
Code:
CREATE TABLE IF NOT EXISTS `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `val` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `val` (`val`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8
3) The view is empty

When I open http://mysite/test/one/ , I see THREE rows added to a database per, instead of 1. There’s must be only 1 row, but there’re 3!! IT’S UNBELIEVABLE! I renamed site_before_footer into site_before , and problem become solved. But when I renamed this into a_b_c, problem appeared anew!! I tried it many times - it’s real magic! It seems like a view can’t have a name like string_string_string.

Guys, please try my code. Does it produce these bugs on your machine ??

I use CodeIgniter 2.1.0


$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]Stefan Hueg[/eluser]
It's working as intended on my machine, using exactly the same code and site_before_footer as the view name.

Did you try that with a fresh CodeIgniter 2.1.0 installation?


$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]PaulBY[/eluser]
Yes Stefan, I tried to run this code on the new CodeIgniter 2.1.0 installation, and the same problem appears. Sad
I enabled profiler and only one query appears:
Code:
DATABASE:  test   QUERIES: 1  (Hide)
0.0004   INSERT INTO test VALUES ('','10')
But how can I get 3 rows this way ?
Do you have any thoughts about this?
I run MySQL 5.1.61-0+squeeze1


$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]Stefan Hueg[/eluser]
Could you enable logging, use log_message('error', 'test') in your controller function and look how many times your code is executed?

This may be an htaccess / web server problem.


$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]PaulBY[/eluser]
I've tried to run this code via comand line
Code:
php index.php test one
It produce only one row. It works normal via command line.


$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]Stefan Hueg[/eluser]
Do you use an .htaccess file? If yes, paste it please.

Else could you paste your webserver's configuration?


$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]PaulBY[/eluser]
I've tested it on a clean CI, there's no .htaccess file.
Apache2 configs:
site_available/test
Code:
<VirtualHost 127.0.0.1:80>
        ServerAdmin webmaster@localhost
        ServerName test
        DocumentRoot /home/paul/www/test
        <Directory /home/paul/www/test/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog /home/paul/www/test.error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /home/paul/www/test.access.log combined

</VirtualHost>
Mods enabled:
Code:
alias.conf       autoindex.conf  mime.conf  rewrite.load
alias.load       autoindex.load  mime.load  setenvif.conf
auth_basic.load       cgi.load       negotiation.conf setenvif.load
authn_file.load       deflate.conf    negotiation.load status.conf
authz_default.load    deflate.load    php5.conf  status.load
authz_groupfile.load  dir.conf       php5.load
authz_host.load       dir.load       reqtimeout.conf
authz_user.load       env.load       reqtimeout.load
apache2.conf
Code:
LockFile ${APACHE_LOCK_DIR}/accept.lock

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15

##
## Server-Pool Size Regulation (MPM specific)
##

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>



$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]PaulBY[/eluser]
Code:
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# event MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_event_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#

AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain


#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

# Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf

# Include all the user configurations:
Include httpd.conf

# Include ports listing
Include ports.conf

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
Include conf.d/

# Include the virtual host configurations:
Include sites-enabled/

Include /etc/phpmyadmin/apache.conf



$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]PaulBY[/eluser]
ports.conf
Code:
NameVirtualHost 127.0.0.1:80
Listen 80
ServerName localhost

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>



$this->db->insert creates 3 rows instead of 1. This bug depends from a name of a view (unbelievable but true) - El Forum - 05-07-2012

[eluser]Stefan Hueg[/eluser]
Hum I don't see anything special in your config.

Have you figured out how many times your code is getting executed by logging it?