AzeS Posted January 1, 2017 Share Posted January 1, 2017 Im trying to read two specifec columns from the user profile, i cant read them, i cant return them but evantually i can check them by an if staetment Public function get($ADDRESS) { try { $sql = $this->Db->prepare("SELECT OID,SLEEP FROM profiles WHERE ADDR=:e"); $sql->execute(array(':e' => $ADDRESS)); $res = $sql->fetchAll(); #var_dump($res); echo "S::::-"; echo $res['SLEEP']; echo "-::::EOS"; if (count($res)) { if ($res['SLEEP'] == 1 ) { return 0; } echo "D:::::-"; echo $res["ESTABLISHED_SINCE"]; echo "-:::::EOD"; $OID = $res['OID']; echo ":::::-"; echo $OID; echo "-:::::"; $sql = $this->Db->prepare("SELECT * FROM plout WHERE owner=:e"); $sql->execute(array(':e' => $OID)); $res_get_layout = $sql->fetchAll(); echo "string;:"; var_dump($res_get_layout); if (count($res_get_layout)) { $sql = $this->Db->prepare("SELECT * FROM postss WHERE ownerid=:e AND CANCELED=:f"); $sql->execute(array(':e' => $OID, ':f' => 0 )); $res_get_posts = $sql->fetchAll(); if (count($res_get_posts)) { $stack = array('POSTS' => $res_get_posts, 'LAYOUT' => $res_get_layout); var_dump($stack); return $stack; } else { return 0; # FATAL(REPORT) } } else { return 0; # FATAL(REPORT) } return 1; } else { return 0; } } catch (PDOException $ex) { echo $ex->getMessage(); return 0; } Quote Link to comment https://forums.phpfreaks.com/topic/302845-what-am-i-doing-wrong-agian/ Share on other sites More sharing options...
NotionCommotion Posted January 1, 2017 Share Posted January 1, 2017 Maybe more, but your array element shouldn't be :e but just e. $sql->execute(array('e' => $ADDRESS)); Quote Link to comment https://forums.phpfreaks.com/topic/302845-what-am-i-doing-wrong-agian/#findComment-1540930 Share on other sites More sharing options...
Jacques1 Posted January 1, 2017 Share Posted January 1, 2017 The code is a mess. I see the same problems in many of your threads, and I've pointed them out multiple times. It would be great if you actually learned from them: Stop rAnDoMlY CHanGIng ThE lETer CASE. Identifiers in PHP (and the various database systems) are almost always lowercase. So it's “public” instead of “Public”, “$address” instead of “$ADDRESS”, “sleep” instead of “SLEEP” etc. This is not just a cosmetic issue. Mixing name conventions massively increases the error rate and decreases readablity. Use meaningful names. Looking at the method signature, I have absolutely no idea what the method is supposed to do. In fact, the name “get” indicates that it's a getter, but obviously it does something entirely different. Your table names “plout” and “postss” can also be improved. Don't use magic return values to indicate the result. In fact, don't use magic numbers at all. The function sometimes returns 0, sometimes 1 and sometimes an array. Again, nobody has the slightest idea what that even means. In a couple of months, even you probably don't know. If there's an error, just throw an exception. Don't randomly catch PDO exceptions. When there's a database error, you almost always want PHP to abort the script in a controlled manner and not keep running. A debugger can help you avoid cluttering your code with echo and var_dump() statements (but I understand this can be a challenge for a beginner). Before you start typing on your keyboard, make a plan of what you want to do. What is the purpose of the method? Maybe more, but your array element shouldn't be :e but just e. It doesn't matter. Both is valid. 1 Quote Link to comment https://forums.phpfreaks.com/topic/302845-what-am-i-doing-wrong-agian/#findComment-1540932 Share on other sites More sharing options...
Solution AzeS Posted January 6, 2017 Author Solution Share Posted January 6, 2017 $res = $sql->fetch(PDO::FETCH_ASSOC); Quote Link to comment https://forums.phpfreaks.com/topic/302845-what-am-i-doing-wrong-agian/#findComment-1541081 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.