PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 8, 2022

[FIXED] SQL query using code igniter

 February 08, 2022     codeigniter     No comments   

Issue

How can I write this query to a code igniter query?

WHERE
  SmallVersion.ID =
  (
    SELECT ChildSmallVersionID AS ID FROM SmallVersion
    WHERE ID = $id
  )

this is how is looks so far:

         ->where('SmallVersion.ID', ("SELECT `ChildSmallVersionID` AS ID
                  FROM `SmallVersion` WHERE ID = $id"));

Solution

Mateusz Wojtula's answer looks ok but you can protect your query

$strSubQuery = $this->db
    ->select("ChildSmallVersionID AS ID")
    ->from("SmallVersion")
    ->where("ID",$id)
    ->get_compiled_select();

$where = "SmallVersion.ID = (".$strSubQuery.")";
$this->db->where($where, NULL, FALSE);


Answered By - sintakonte
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing