underscore in php db variable causing problems

☆樱花仙子☆ 提交于 2019-12-01 06:01:27

Nothing I can find in the PDO documentation suggests that you can specify username or password in the DSN string - it is a "Database Source Name" not "Database Source Name and Authentication" String the fact you are using no password should be a hint to this, and the username being 'myname' is probably just because most RDBMs use the $USER environment var to connect if none is specified (which i must assume is set to 'myname')

i.e. i think you simply have to use the extra parameters to pass the authentication credentials

As a work around I built get functions in the file that the information is stored that return the strings, and it works. Super strange, but it works.

you should get the same result from appending quotes

 ////the variable
 $myusr='myname_user'; 

////now append quotes
    $user="'".$myusr."'"; 

///which would be the same thing as
  $psswd= "'pass_word'";

the pdo function will strip out the single quotes ( ' ' ) if you wanted to store it with quotes it would be '\'password\'' in your sql statement as stored quotes must be stored with delimiters to prevent auto escaping.

  INSERT INTO `Auth_USERs` (`id`, `usrname`, `passwd`, `email`, `reg_date`) VALUES (NULL, '\'myname_user\'', '\'pass_word\'', 'someone@somewhere.com', CURRENT_TIMESTAMP);

you came across the {} as this treats the variable as inside a container, so it appends ' ' of course the get array does this too (with different characters, then php escapes them on next page load ) since you're executing a java function to make your get functions, you are essentially appending quotes that are not escaped. Until PDO function escapes them.

$this -> DB = new PDO ("mysql:host={$hostname};dbname={$dbname}", $user, $psswd);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!