1,105,456 Community Members

SQL Query Works, But Not In PHP

Member Avatar
Navlag
Light Poster
34 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I tested and successfully used this SQL code below to input data into a database.

    INSERT INTO hraps (id, firstname, lastname, gender, year_of_1st_rappel, count_offset_proficiency, count_offset_operational, spotter) values(111111, 'World', 'Hello', 'Male', '2007', '1', '2', '0')

Now I'm trying to integrate it into PHP like this:

     $query = "INSERT INTO hraps (firstname, lastname, gender, year_of_1st_rappel, count_offset_proficiency, count_offset_operational, spotter) "
    ."values('".$this->firstname."','".$this->lastname."','".$this->gender."','".$this->year_of_1st_rappel."',".$this->count_offset_proficiency.",".$this->count_offset_operational.",".$this->spotter.") returning id into :id";

    $dbid = "";
    $binds = array();
    $binds[] = array("name" => ":id", "value" => &$dbid, "length" => 128);
    //echo $query;              
    $result = mydb::cxn()->query($query, $binds);
    $this->id = $dbid;

But nothing gets inserted and I'm not getting any error. The only difference is that in this one I'm defining id as $dbid, and before I hard-coded it in the "values" section of the query.

Can somebody please point out why this code is not working successfully?
Thank you.

LastMitch
Deleted Member
 
0
 

But nothing gets inserted and I'm not getting any error. The only difference is that in this one I'm defining id as $dbid, and before I hard-coded it in the "values" section of the query.

That's not how you INSERT in PHP.

Read this and look closely how to INSERT statement should look like:

http://www.phpeasystep.com/mysql/5.html

Member Avatar
pritaeas
mod_pritaeas
11,315 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

I think the problem is with returning into. Isn't this an Oracle specific construct? Anyway, I am not convinced that you can bind a return value.

Member Avatar
Navlag
Light Poster
34 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I think the trouble lies with this section:

$dbid = "";
$binds = array();
$binds[] = array("name" => ":id", "value" => &$dbid, "length" => 128);

I'm not entirely sure how it's setting the id, to be honest.

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

This certainly looks like Oracle. Is it?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article