Which is faster between php switch case or database query in this context

Wayne :

I have an online php/mysql based Bible search app. Currently it only have 5 book versions.

I am now being asked to add 130+ Bible versions. I am thinking if this will have impact on the performance.

The options I am considering are as follows.

OPTION 1: Hard code the different bookname and use php switch case to determine the book to display. This is my current setup and this is working well for 5 languages currently added on my app. I did it this way because the database I receive only have book number column and has no bookname.

In case language selected is African (same process for all other languages), below code will check book number and apply name appropriately (66 Bible books)

case "101": $book ="101"; $bookword = ("GENESIS" . ' ' . strval($chapter_id) . ':' . strval($verse_id)); break;
case "102": $book ="102"; $bookword = ("EXODUS" . ' ' . strval($chapter_id) . ':' . strval($verse_id)); break;
case "103": $book ="103"; $bookword = ("LIVITIKUS" . ' ' . strval($chapter_id) . ':' . strval($verse_id)); break;
...
case "166": $book ="166"; $bookword = ("OPENBARING" . ' ' . strval($chapter_id) . ':' . strval($verse_id)); break;

This will be run every time user change language selection via pull down menu

OPTION 2: Add a column bookname in each tables (each table is one Bible version) which will mean additional 31 thousand entries for each books. This way, bookname will already be included in the query result. In option 1, only book number is available after query. I have to use the php switch case to add bookname.

Will there be significant difference between these 2 in terms of performance.

Daan Wilmer :

No, there won't be a significant difference in performance. Databases are made for this sort of thing, and maintaining the code for this manually would be hell (and error-prone).

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=402156&siteId=1