Jump to content

Var With Hyphens In Sql Record


Blesta Addons

Recommended Posts

Hello ,

 

first , i know that using hyphens "-" in a variable is not recommanded , we should use "_" instead . but for a porject i work for it, the client already has a big and tremendous data , and almost is impossible forit to change this , and we are forced to work the hyphens .

 

i get a sql query error

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-`depends`='12346',`status`='active'' at line 1 on line .....

i have the fallowing code in a model

$fields = array("package", "name", "version", "depends" , "pre-depends",  "status"   );
 
$this->Record->where("id", "=", $package_id)->update("packages", $vars, $fields);

when i remove the "pre-depends" from the fields it work perfectly .

 

i have tried  "{pre-depends}" ; "pre\-depends" without success .

 

 

how i can pass this without hacking he core record.php ?

Link to comment
Share on other sites

maybe you could include a variable conversion list like

 

$original-variable1 =  $variable1;

$original-variable2 =  $variable2;

etc...

 

 

in adition function like preg_replace();

can remove the dash from a given list, but it realy depend if you need something dynamic or just like above static list is enought

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.

Loading...
×
×
  • Create New...