We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,633 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

SQL Query Works, But Not In PHP

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.

4
Contributors
4
Replies
2 Days
Discussion Span
3 Months Ago
Last Updated
17
Views
Navlag
Light Poster
34 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

LastMitch
Industrious Poster
4,118 posts since Mar 2012
Reputation Points: 132
Solved Threads: 334
Skill Endorsements: 45

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.

pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

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.

Navlag
Light Poster
34 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This certainly looks like Oracle. Is it?

diafol
Keep Smiling
Moderator
10,625 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0835 seconds using 2.68MB