Jump to content

What am i doing wrong agian ?


Go to solution Solved by AzeS,

Recommended Posts

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;
 	} 
Link to comment
https://forums.phpfreaks.com/topic/302845-what-am-i-doing-wrong-agian/
Share on other sites

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.

  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.