Jump to content
MakeWebGames

sql "? & array" issue


Recommended Posts

[mysql]$query = $this->db->execute('SELECT `id`, `username`, `level` FROM `players` WHERE `level`<=?, `username`!=? ORDER BY `level` ASC', array($player->level, $player->username));[/mysql]

Can someone tell me how to properly execute this query where level<$player->level & username!=$player->username?

somewhere im wrong at [mysql]`username`!=?[/mysql]

Link to comment
Share on other sites

Not sure if this was what you fixed, but when querying tables, the table name should have the prefix <ezrpg>.

So for this query you need to select from the table `<ezrpg>players`. :)

Oh by the way, this query syntax isn't a mysql error, it's a database class error. Parameter binding isn't used in the php mysql_* functions.

Link to comment
Share on other sites

oh and not everything revloves around your engine, thats why its in MySql :P

Like I said in my reply, this was not a mysql error.

MySQL doesn't have parameter binding in the language. Parameter binding in mysql is usually implemented through libraries. As far as I know, mcc doesn't use parameter binding and jesterc was asking about ezrpg earlier, so i assumed he was talking about ezrpg. I could be wrong but I doubt it.

And yes, I wrote the database class and the method that handles the parameter binding but other database libraries use the same format.

Anyways, the problem was fixed, topic should be closed if there's nothing left to comment :P

Link to comment
Share on other sites

  • 3 weeks later...

MySQL doesn't have parameter binding in the language True

MySQLi on the other hand has the bind_params() function, replacing the ?

the way I see that code should look like

 

$db = new mysqli();

$sql = "SELECT .... FROM ... WHERE x = ? AND z = ?"

$query = $db->prepare( $sql );
echo $db->error;
$query->bind_param( 'ss', $level, $username );
$query->execute();

 

or that execute() ? it's a function you made that isn't part of Mysqli?

I'm glad you solve it.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...