php操作 mysql資料庫簡單分表原理-帶詳細步驟

來源:互聯網
上載者:User
query("$sql");// }//建立一個id儲存表,其實也沒必要非得叫id,如果業務量大按年月日也行, 按增量也行。// CREATE TABLE `test`.`create_id` (`id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE = MYISAM;//建立一個總表 ,有沒有必要自己體會(後期用到分頁,統計的時候直接調用就行,查詢的速度還是很快的,如果不想要這個表,那就用的時候再用union查詢:把所有表名放入數組中,然後foreach 在拼裝sql .union 去。所以還不如開始的時候做好呢)// CREATE TABLE `article_total` (//   `id` bigint(20) NOT NULL,//   `subject` varchar(200) NOT NULL,//   `content` text NOT NULL,//   PRIMARY KEY (`id`)// ) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 UNION=(`article_0`,`article_1`,`article_2`,`article_3`);// Query OK, 0 rows affectedfunction get_AI_ID(){global $mysqli;$mysqli->query('insert into create_id (id) values("")');// 返回插入id值return mysqli_insert_id($mysqli);}function new_article(){global $mysqli;echo $id=get_AI_ID();echo $table_name=get_table_name($id);$sql = "insert into {$table_name} (id,subject,content) values('{$id}','title','content')";echo $sql;$mysqli->query($sql);}function get_table_name($id){return 'article_'.intval($id)%10;}new_article();

以上就介紹了php操作 mysql資料庫簡單分表原理-帶詳細步驟,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.