Php 我不想在mysql中的每个表之前都保留dbname
我已经在IIS、windows 2012中安装了带有数据库的php网站,问题是,如果我在网站中的每个查询的表名之前提到db名称,这是可以接受的。下面的例子Php 我不想在mysql中的每个表之前都保留dbname,php,mysql,database,Php,Mysql,Database,我已经在IIS、windows 2012中安装了带有数据库的php网站,问题是,如果我在网站中的每个查询的表名之前提到db名称,这是可以接受的。下面的例子 select userid,profile_id,email,first_name,last_name,password,login_flag,usertype from reqsbook.user where email='$email' and password='$password' and usertype='$user
select userid,profile_id,email,first_name,last_name,password,login_flag,usertype
from reqsbook.user
where email='$email'
and password='$password'
and usertype='$usertype'
实际上,我曾经在LinuxWeb服务器上运行过这个网站,但根据我的客户端要求,我已经在iis服务器上安装了它。
请让我知道,在我的项目中的所有查询中,是否有可能在表之前删除db名称,或者我是否可以将db名称保留在一个位置,以便universal执行此操作,假设您的数据库名称为
reqsbook
USE reqsbook代码>从php连接到dbms后,在给出任何选择或其他查询之前立即执行
$mysqli=newmysqli('hostname','username','REDACTED_PASSWORD','reqsbook')代码>
$db=newpdo('mysql:host=hosthame;dbname=reqsbook','username','redact_PASSWORD')代码>
如果您使用的是
mysql\uuu
,那么,除非您希望您客户的应用程序被网络犯罪分子攻击,否则请停止这样做。您需要在连接上设置活动数据库。您存在SQL注入漏洞。不要以纯文本形式存储密码!调用mysqli_connect
或new PDO
打开连接时,可以指定默认数据库。那么你就不必在查询中输入数据库名了。非常感谢你的回答,这对我很有用