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;