-1

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;
vBulletin
  • 3
  • 3

1 Answers1

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

Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33