Karaethon Posted March 29, 2019 Share Posted March 29, 2019 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... 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. 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. 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? Link to comment Share on other sites More sharing options...
benanamen Posted March 29, 2019 Share Posted March 29, 2019 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 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. 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. 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". 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) 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.... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.