Karaethon Posted March 29, 2019 Share Posted March 29, 2019 (edited) I am getting Fatal error: Uncaught Error: Call to a member function real_query() on null with this code: public final function Retrieve($TABLE, $CRIT){ $_query = "SELECT * FROM `{$TABLE}` WHERE "; foreach($CRIT as $_field => $info){ $_query .= " `{$_field}` = `{$info}` &&"; } if($this->LINK->real_query(rtrim($_query, ' &'))){ return $this->LINK->store_result(); } else{ return json_encode(array("Error"=>$this->LINK->errno(), "Description"=>$this->LINK->error())); } } (LINK is my mysql_connect() result.) I have tried everything i can think of, ->query, going to mysqli_query, breaking it sown and using a $result variable, but nothing seems to work... Edited March 29, 2019 by Karaethon Quote Link to comment Share on other sites More sharing options...
requinix Posted March 29, 2019 Share Posted March 29, 2019 12 minutes ago, Karaethon said: (LINK is my mysql_connect() result.) Actually it isn't. If it was then the error wouldn't be happening. Quote Link to comment Share on other sites More sharing options...
Karaethon Posted March 29, 2019 Author Share Posted March 29, 2019 Good catch! I want to copy and paste my __construct code to show what I had and I noticed it was $LINK = mysqli.... instead of $this->LINK = mysqli.... I looked at it 500 times but kept missing it because I saw what I expected, not what was. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 29, 2019 Share Posted March 29, 2019 Why the double &? Isn't one enough in an sql statement? Quote Link to comment Share on other sites More sharing options...
benanamen Posted March 29, 2019 Share Posted March 29, 2019 (edited) 45 minutes ago, ginerjm said: Why the double &? Isn't one enough in an sql statement? No. https://dev.mysql.com/doc/refman/8.0/en/logical-operators.html Edited March 29, 2019 by benanamen Quote Link to comment Share on other sites More sharing options...
Karaethon Posted March 30, 2019 Author Share Posted March 30, 2019 Habit. I am used to thinking && instead of AND when writing code. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 30, 2019 Share Posted March 30, 2019 Now that it has been pointed out to me that 2 &'s are necessary I suddenly realize that I have never seen anyone NOT use 'AND' in their queries. For PHP, yes && is the rule. Quote Link to comment Share on other sites More sharing options...
requinix Posted March 30, 2019 Share Posted March 30, 2019 16 minutes ago, ginerjm said: Now that it has been pointed out to me that 2 &'s are necessary I suddenly realize that I have never seen anyone NOT use 'AND' in their queries. For PHP, yes && is the rule. MySQL also supports || and !, but SQL has been designed to look human-readable so people normally use OR and NOT instead. As opposed to PHP's && and ||, which are actually subtly different than "and" and "or". Quote Link to comment Share on other sites More sharing options...
Barand Posted March 30, 2019 Share Posted March 30, 2019 2 hours ago, requinix said: As opposed to PHP's && and ||, which are actually subtly different than "and" and "or". Just to confirm Requinix's statement by psedocode examples This works: result = query(sql) or die(error message) Whereas this doesn't result = query(sql) || die(error message) Quote Link to comment Share on other sites More sharing options...
Karaethon Posted March 31, 2019 Author Share Posted March 31, 2019 18 hours ago, Barand said: Just to confirm Requinix's statement by psedocode examples This works: result = query(sql) or die(error message) Whereas this doesn't result = query(sql) || die(error message) Hmm, yeah I kinda knew that, never really thought of how it would affect execution... In this case I dont think I could use AND though because the rtrim after completion could remove more than the AND? or maybe not it is only trimming from end.... Quote Link to comment 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.