Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
How to check if rows exist PDO PHP?

I'm learning PHP PDO and I need some help with codes. I have 2 Questions today.

First Question: How can I check if row exist in table with Network_Code and Niche, if there is column with same ID to proceed, but with same ID and Niche to die message.

    $network_code = $_GET[ 'ID' ];
    $Niche      = $_GET[ 'Niche' ];
    $sql = "INSERT INTO `affiliates` (ID, Niche, Language, lockerURL, Network_Code, Google_ID) VALUES (NULL, '$Niche', '$Language', '$domain', '$network_code ', '$Google_ID')";

    $query = $pdo->prepare( $sql );
    $query->execute();

Second Question: Is there any other way that I can use: $system_default[ 0 ]->column because I think that is wrong way, so I need something like this: $system_default->column class default_system {

    function __construct( $pdo ) {

        $this->pdo = $pdo;

    }

    function getData() {

        $ID     = $_GET[ 'id' ];

        $Niche  = "clash-clans";

        $query = $this->pdo->prepare( "SELECT * FROM `affiliates` WHERE `Network_Code` = '$ID' AND `Niche` = '$Niche'" ); 
        $query->execute();  

        return $query->fetchAll( PDO::FETCH_OBJ ); // Return an Array of objects

    }

}   

$db_system = new default_system( $pdo );
$system_default = $db_system->getData();

echo $system_default[ 0 ]->lockerURL;
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Below example for First Question, you can try to solve your problem certain ways below is example of it. you can read more about pdo from here

$query=$dbh->prepare("SELECT secret FROM users WHERE username=:param");
$query->bindParam(':param', $param);
$query->execute();
$result = $query -> fetch();
print_r($result);

For second issue

echo $system_default['lockerURL'];

and remove echo $system_default[ 0 ]->lockerURL; line

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!