![]() |
|
C++, PHP and MySQL, or just C++ and MySQL?. |
AMCerasoli
Member #11,955
May 2010
![]() |
Hi there, this is just a comment. I would like to know what kind of approach would you prefer to use in this situations. I was using PHP to modify my own database (just a simple file) but now I want to use MySQL. So... I was using libCurl to send the request using POST fields etc. Now, there is MySQL++, which allows me to send and retrieve info, and I wouldn't need to use PHP or libCurl. So what of these approach would you use?
Personally I would use number 1, because I want to learn more about PHP, but using it for what I see, using PHP as intermediary isn't not necessary so practically it's double work isn't?
|
van_houtte
Member #11,605
January 2010
![]() |
PHP+MySQL is insanely easy to learn and use, i've used it to solve countless problems really quickly ----- Sometimes you may have to send 3-4 messages |
Mark Oates
Member #1,146
March 2001
![]() |
Do 'em all. There's also Boost.Asio for socket programming. -- |
bamccaig
Member #7,536
July 2006
![]() |
I would say that it depends on the problem. I'm assuming C++ isn't optional then. It otherwise depends on how serious the project is and how much you want to learn. I would say that using PHP as an intermediary you would learn more about libcurl than about PHP. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Oscar Giner
Member #2,207
April 2002
![]() |
2 implies that you need to allow external connections to the database, which in general is not a good idea for security reasons. If you're using a web hosting service (specially if it's free) external access to the database is probably not even allowed. Option 2 also forces you to GPL your program (unless you buy a commercial MySQL license), if that matters to you. You can say that option 1 is overkill: having a full web server just for a simple application, though it's easier to implement. There's an option 3, which would be writing your own server software. -- |
AMCerasoli
Member #11,955
May 2010
![]() |
van_houtte said: PHP+MySQL is insanely easy to learn and use, i've used it to solve countless problems really quickly Yhea I have been reading MySQL and it's so easy. I have a simple file which consist in this: name Like... Jhone and it's a really pain to read it from my program, and I haven't done the part where I modify the names and times depending in which is higher using PHP... With MySQL it's much more simple. after retrieving the file look what I'm doing: 1 std::stringstream procesador(p_dato->string);
2
3 short aa=0;
4 short aaa=0;
5
6 for(int a=1;a<31;a++){
7
8 if(a & 1){
9
10 char temporal[50];
11
12 procesador.getline(temporal, 50);
13
14 al_ustr_free(p_dato->nombres[aa]);
15
16 p_dato->nombres[aa] = al_ustr_new(temporal);
17
18 // Se elimina el caracter /r ya que getline solo elimina /n, y windows usa ambos.
19 if(al_ustr_has_suffix_cstr(p_dato->nombres[aa], "\r"))
20 al_ustr_remove_chr(p_dato->nombres[aa], al_ustr_offset(p_dato->nombres[aa], -1));
21
22 aa++;
23 }
24 else{
25
26 char temporal[50];
27
28 char min_T[30], seg_T[3];
29
30 procesador.getline(temporal, 50);
31
32 short segundos_T = atoi(temporal);
33
34 short min = 0, seg = 0;
35
36 for(;segundos_T > 0; segundos_T--){
37
38 seg++;
39 if(seg>59){ min++; seg=0; }
40
41 }
42
43 sprintf(min_T,"%02d",min);
44 sprintf(seg_T,"%02d",seg);
45
46 al_ustr_append_cstr(p_dato->tiempos[aaa], min_T);
47 al_ustr_append_cstr(p_dato->tiempos[aaa], ":");
48 al_ustr_append_cstr(p_dato->tiempos[aaa], seg_T);
49
50 if(al_ustr_has_suffix_cstr(p_dato->tiempos[aaa], "\r"))
51 al_ustr_remove_chr(p_dato->tiempos[aaa], al_ustr_offset(p_dato->tiempos[aaa], -1));
52
53 aaa++;
54
55 }
56 }
It's really a mess... Since I'm storing the time like: "356 seconds" then I need to convert them to minutes and seconds... I think for all the MySQL is the answer. bamccaig said: I would say that it depends on the problem. I'm assuming C++ isn't optional then. It's just for my game Oscar Giner said: Option 2 also forces you to GPL your program (unless you buy a commercial MySQL license), if that matters to you. Wow, that is really a good point. Basically I want to add some extra functions to my game, there is already two modes; Winer Mode: The game takes the best time from the list (which is taken from the server) and start the game in countdown, when the time finish, that means that you're not going to appear first in the list, so it's pointless to still playing. Normal Mode: The game uses a normal clock taking the time you took to finish the game (answering all the question) and put it on the list if you're in the first 15 best times. But now I want to add an extra mode, and would be playing with online questions, basically everybody is able to create its own database and connect to it and play with the questions that are registered to that database. So suppose that someone create the "Hallowing" database and start adding questions to it, if someone wants to connect to that database just introduce the name of that database and connects... So yhea for all that, I will need MySQL for sure... But using PHP as intermediary would take a little bit of more work but I think it's worth it. Look what I did!
|
Tobias Dammers
Member #2,604
August 2002
![]() |
If the goal is to maintain a highscore list, then MySQL is way too large. Have you looked into SQLite? It's perfect for the job - you get one file containing the entire database, and the entire database engine gets linked into your program, so you don't have to make the user install a database server. --- |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
If this is for an online high-score list, I would go with PHP + mysql. You should probably never expose a database server to the general population
|
AMCerasoli
Member #11,955
May 2010
![]() |
Tobias Dammers said: If the goal is to maintain a highscore list, then MySQL is way too large. Have you looked into SQLite? Yes, the problem is that my web hosting doesn't support it. Jonatan Hedborg said: If this is for an online high-score list, I would go with PHP + mysql. Yhea me to, I'm going to use MySQL + PHP + libCurl. Learning libCurl allows me to get experience in HTTP request while PHP + MySQL give me experience for webs too, you konw, using HTML/JavaScript... instead of C++. Oscar Giner said: 2 implies that you need to allow external connections to the database, which in general is not a good idea for security reasons. Jonatan Hedborg said: You should probably never expose a database server to the general population
I didn't know those security problems, that is a big problem too...
|
Tobias Dammers
Member #2,604
August 2002
![]() |
AMCerasoli said: Yes, the problem is that my web hosting doesn't support it. Oh, you're on a web host. In that case, I misread your question. If you want to maintain an online highscore list, then the canonical implementation would be a MySQL database, on top of that a PHP web service (don't bother with SOAP, just send JSON data using GET and POST), and then on the client something around libcurl to access the web service. A particularly nasty problem in this scenario is that you need to secure access to the web service, otherwise anyone can figure out how it works and send spoofed scores, pretty much voiding the entire purpose of the highscore list. You need to make sure that the request really comes from a legit client; unfortunately, there is no 100% secure solution, other than putting all the program logic on the server. --- |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
A "good enough" way might be to send on a hash of the data with the request. Maybe a MD5 hash where every other character is xor'd with the other.
|
AMCerasoli
Member #11,955
May 2010
![]() |
Well.... Following the Mark Oates suggestion... I'll use them all... Check this out. Tools: C++: We all know why I'm using this. So the game should have: - A SQLite database with the official Question_Packages. I think the MySQL database should have the next fields: ID, Ques_Pack_Name, URL_of_file, downloads, creation_data, update_data, amount_of_questions, it's_editable, password, Username, description ... and optionally in the same table the 15 best scores but I'm not sure. The bad news is that there is a loooooooooooooooooooooooooooooot of work. The good news is that I'm able to do it. So what do you think?
|
bamccaig
Member #7,536
July 2006
![]() |
It sounds reasonable, though I would probably eliminate the "editable" stuff and just make all user-submitted packages editable (i.e., open). It's not like you can really prevent it anyway. Otherwise, your database schema sounds horribly de-normalized, but I'm too tired and/or lazy right now to actually think about it. Since you will be storing a password I feel obligated to point out that you should never store plain text passwords, especially of users. Salt and hash them (one-way cipher) and store that. Do the same to their inputs when you need to compare for authentication. You might also warn your users not to use "good" passwords so they don't use e.g., their online banking password with your game. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
MiquelFire
Member #3,110
January 2003
![]() |
For passwords, crypt with blowfish, 15 or 16 is good right now (later on, you'll need to update this value over time, but that would be in a few years) The slowest time I have reported for 16 is around 7 seconds (and it's 3.5 seconds for 15) --- |
Neil Walker
Member #210
April 2000
![]() |
Tobias Dammers said: Have you looked into SQLite? If the goal is to maintain a highscore list, then SQLite is overkill. My high-score data stored in a csv, is read, split and sorted using standard STL containers/algorithms, no need for fancy database libraries. Only takes a few lines of code. I then upload scores and download high-score tables using libcurl and on uploading the server splits the csv and sticks it in a mysql table. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
|