Welcome Guest, Not a member yet? Register   Sign In
Anybody trying to use i5/iSeries database?
#1

[eluser]clutton[/eluser]
Hi all,

I have been just starting out with some PHP coding and am interested in using data and storing data back to our IBM DB2 database where our ERP system resides. I have been attempting to use the db2c drivers from the wiki page but am having trouble when trying to insert data. My code looks like this:

Code:
function addDriver($name) {

        //$data = array(
        //    'DR_NAME' =>  $name
        //);    
        //$this->db->insert('drivers', $data);
        
        $sql = "INSERT INTO drivers (dr_name)
                    VALUES (".$this->db->escape($name).")";

        $this->db->query($sql);
        
    }

I have tried it using both ways above and they do not seem to submit the query when a value is in the "name" variable. The fun part is that it works if $name is blank. It is probably something very simple but I am not seeing it. Anyone using the db2c driver with any luck on an iSeries? Thanks in advance for any suggestions.
#2

[eluser]echoDreamz[/eluser]
[quote author="clutton" date="1286227451"]Hi all,

I have been just starting out with some PHP coding and am interested in using data and storing data back to our IBM DB2 database where our ERP system resides. I have been attempting to use the db2c drivers from the wiki page but am having trouble when trying to insert data. My code looks like this:

Code:
function addDriver($name) {

        //$data = array(
        //    'DR_NAME' =>  $name
        //);    
        //$this->db->insert('drivers', $data);
        
        $sql = "INSERT INTO drivers (dr_name)
                    VALUES (".$this->db->escape($name).")";

        $this->db->query($sql);
        
    }

I have tried it using both ways above and they do not seem to submit the query when a value is in the "name" variable. The fun part is that it works if $name is blank. It is probably something very simple but I am not seeing it. Anyone using the db2c driver with any luck on an iSeries? Thanks in advance for any suggestions.[/quote]

Try
Code:
$sql = "INSERT INTO drivers (dr_name) VALUES ('{$this->db->escape($name)}')";
#3

[eluser]clutton[/eluser]
Thanks for the reply, I tried that and it gives an error about trying to convert to a string which makes sense to me as it is concatenating together the string.

I have setup a MySQL version of the database and used both versions of the database insert code and all seems to be fine when interacting with MySQL. Perhaps it has to do with the db2c driver and the current CI. I'm not sure how to go about fixing it .... so I may just have to use a MySQL database for now until I get more familiar with things. Kind of a shame since it would be nice to have the data with the ERP data for ease of backup and integration later on. As with most things iSeries, sometimes things are a little more difficult than it would seem.
#4

[eluser]echoDreamz[/eluser]
Yes. Unfortuantely MySQL, and Microsoft SQL server about the 2 most common forms of database backends with PHP. Postgre is used too, but not as much as the 2 above. I have never seen anyone using DB2 nor do I have any experience with it Smile. Sorry I was not able to assist Sad.
#5

[eluser]echadwickb[/eluser]
I am using the db2c driver quite successfully with 1.7.2 on V6R1. I do not use the escape function in the db library, though. I use the basic function str_replace("'","''", $field) inside my models.

To get db2c driver working, I also had to comment out the line:

$sql = $this->_prep_query($sql);

from db2c_driver.php. Once I did that, it worked fine.
#6

[eluser]Victor Michnowicz[/eluser]
It may be adding backticks (`) ?

If you turn on profiling you can check out the query:

Code:
$this->output->enable_profiler(TRUE);

I have never used anything but MySQL thou, so I am just guessing here.
#7

[eluser]echadwickb[/eluser]
Actually, I think it was the back ticks that were causing the issue. Regardless, the _prep_query() was not necessary
#8

[eluser]echadwickb[/eluser]
Clarification on my last post. The issue is db2_escape_string() uses backslashes as an escape character, when db2 on i wants a single quote: So "O'Mally" needs to be "O''Mally" instead of "O\'Mally".




Theme © iAndrew 2016 - Forum software by © MyBB