如何PHP根据uid计算出来插入哪个数据库?
我现在要实现一个功能:
要通过计算规则计算出来200w用户的uid,对应insert日志不同的表,如何计算出来,是的表均衡处理?
回复讨论(解决方案)
是的日志进行均衡访问,不会导致每个表数据量很大,如何实现,高手们,指点指点
使得日志进行均衡访问,不会导致每个表数据量很大,如何实现,高手们,指点指点
uid 通常是数字,取模就可以了
substr('1456', -1);//6
根据uid的个位数就知道存在哪个表(0-9,10个表)
请高手们给与代码作为参考啊,谢谢
这需要代码吗?
令 $uid 为 uid 的值, $m 为日志表数
则表名 $tbl = '前缀' . ($uid % $m)
不知道你的多个表的命名规则 是什么? 是 200W 个用户,随机分配日志表,还是这个用户被创建时,就要指定放到哪张表?
1. 如果是随机的话,最好表的命名有一定的规则 ,比如:log001 , log002 ..., log100 这样子。直接用 rand() 加工一个数字出来,再拼成表名称;
2. 如果用户被创建时,就指定了写哪个表,就更好办了,在用户登录时,就把这个表名写到 session 中,写日的时候,直接拼接;
3. 如果,你想根据用户的第一位字符来确定,也可以采用方法 2 ;
有没有代码生成器,自动生成出出来表,假如我现在200W会员,生成300张表,谁有代码可以先把表生成出来,然后根据uid自动计算出来要insert那个表名?请给与代码
你先要定义好一个表,然后
for($i-0; $i<300; $i++) mysql_query("carete table log_$i select * from 表 where 1=0“);
插入时的表名计算我在 #6 已经给了
这是得多么频繁的操作数据库啊。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.
