dragon8002 2019-05-05 11:52
浏览 99

什么是在PHP中保存多个MySQL数据库连接的解决方案

I need a solution for save every MySQL connections in PHP and use it in sql transactions between connections.

I know that I can't do transactions between different connections but I want to handle in PHP or a solution. (I don't know "what is the solution?")

Is that right, about :

  • security?
  • performance?
  • transaction?
  • ...

completing question :

I have multiple databases that connected with different users. One or more database are common between other databases that use it on the joins, for example :

db_common with common_user and tables: common_1, common_2, ...
db_specific_1 with user_1 and tables: s1_1, s1_2, ...
db_specific_2 with user_2 and tables: s2_1, s2_2, ...

May be join db_specific_1 with common or even with db_specific_2.

I want to remove joins between databases. Because, db_specific_1 is for a project and db_specific_2 is for other project. Since the database server is the same one, I granted select access to user_1 to db_specific_2, that is wrong, since db_specific_2 must be transfer to other server.

I need transaction between db_specific_1 and db_specific_2 and db_common.

  • 写回答

1条回答 默认 最新

  • douqin1932 2019-05-05 12:52
    关注

    I setup the access rights so that each project needs only one database connection. Usually each project has a main part of a database. For example:

    grant all on `database`.* to `username`@localhost
    

    If the same user have full access to another database2, I add

    grant all on `database2`.* to `username`@localhost
    

    But usually, only some tables or columns must be accessed, and sometime only readonly:

    grant select on `database2`.stats to `username`@localhost
    

    In PHP use database.table instead of table to select foreign tables:

    SELECT a.name, b.stat 
    FROM `mytable` a 
    LEFT JOIN `database2`.`stats` b ON b.id = a.id
    
    评论

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程