PDO 数据库连接空格引发错误!
好吧,我是一个喜欢间隔代码的人,我发现它更容易阅读、编辑和理解。目前php.net上使用PDO连接mysql的方式如下;
$dbc=new PDO('mysql:host=localhost;dbname='table', 'root', 'password');
我喜欢我的资格,所以我像这样编辑添加空格;
$dbc = new PDO('mysql:host = localhost; dbname = 'table', 'root', 'password');
这样做会引发错误,这并不是一个问题,因为它根本不关心我,但我认为 php 不考虑空格?那么为什么会出现错误呢?
Ok so I am one for spacing out my code, I find it easier to read, edit and understand. The current way to connect to mysql with PDO is as follows on php.net;
$dbc=new PDO('mysql:host=localhost;dbname='table', 'root', 'password');
I like my eligibilty so I edited like this adding whitespace;
$dbc = new PDO('mysql:host = localhost; dbname = 'table', 'root', 'password');
Doing so throws an error, it is not so much as a problem as it doesn't concern me that much at all, but I thought php does not consider whitespace? So why the error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PDO DSN 语法不允许在任何您想要的位置添加空格。
这个语法与常规的php语法规则无关,只是因为它是带有DSN的字符串而不是php。
PDO DSN syntax doesn't allow to add spaces in any place you want.
This syntax has nothing to do with regular php syntax rules, just because it is a string with DSN and not php.