Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: just a query!  (Read 4631 times)

0 Members and 1 Guest are viewing this topic.

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
just a query!
« on: January 30, 2012, 07:36:07 pm »
i need, for my highscores online, send to my database some data.

Then, i really dont know how i can do this.. I thought something like my program send the data to my php page and the page send the query ( i know how to send a query in php ).. its possible? starch could someone help me? perhaps with an example? the documentation did not help me! thank you!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
just a query!
« Reply #1 on: January 30, 2012, 07:40:02 pm »
Quote
I thought something like my program send the data to my php page and the page send the query

Yes, this is usually how it is done. There's really nothing complicated. What is blocking you?
Laurent Gomila - SFML developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
just a query!
« Reply #2 on: January 30, 2012, 07:44:50 pm »
Quote from: "Laurent"
Quote
I thought something like my program send the data to my php page and the page send the query

Yes, this is usually how it is done. There's really nothing complicated. What is blocking you?


how my program can contact the php page, give the data and run the query automatically :(

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
just a query!
« Reply #3 on: January 30, 2012, 08:05:51 pm »
Use sf::Http (SFML 2). You can find an example in the documentation here.
SFML / OS X developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
just a query!
« Reply #4 on: January 30, 2012, 09:41:34 pm »
Quote from: "Hiura"
Use sf::Http (SFML 2). You can find an example in the documentation here.



yah but how from this ->


Code: [Select]
sf::Http http;

 http.SetHost("http://www.bufera.altervista.org");

 sf::Http::Request request("log.php");

 sf::Http::Response response = http.SendRequest(request);

 sf::Http::Response::Status status = response.GetStatus();
 if (status == sf::Http::Response::Ok)
 {
     std::cout << response.GetBody() << std::endl;
 }
 else
 {
     std::cout << "Error " << status << std::endl;
 }




i can send query on my log.php page to mysql database like this ->

Code: [Select]
<?php
$nick
$_GET['Nick'&#93;;
$pass$_GET['PASS'&#93;;
$email$_GET['Email'&#93;;
$ris mysql_query&#40;"INSERT INTO Utente &#40;Nick_id, Pass_id, email_id&#41; VALUES&#40;'$nick', '$pass', '$email'&#41;"&#41;;

?>




???

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
just a query!
« Reply #5 on: January 30, 2012, 10:12:53 pm »
Code: [Select]
sf::Http::Request request("log.php?Nick=xxx&PASS=xxx&Email=xxx");
Or as POST data, so that it's more hidden
Code: [Select]
sf::Http::Request request("log.php");
request.SetBody("Nick=xxx&PASS=xxx&Email=xxx");
request.setMethod(sf::Http::Request::Post);

Code: [Select]
$nick= $_POST['Nick'];
$pass= $_POST['PASS'];
$email= $_POST['Email'];
Laurent Gomila - SFML developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
just a query!
« Reply #6 on: January 30, 2012, 10:38:27 pm »
laurent, thanks, you have been very helpful as always!
I now need is to understand how to send data from mysql into my app XDD

thanks again!

ps: after a year it seems to me that I use SFML time to get my contribute with a *little* donation! :3 Bravo! bye!

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
just a query!
« Reply #7 on: February 06, 2012, 04:17:43 pm »
Oh i have another question..

what if i need to take some datas with this query and save the resultates in my app?

Code: [Select]
while ($riga = mysql_fetch_assoc($ris)) {
echo "<li>".$riga['user']." ".$riga['score']."</li>";



i dont know how much of name there is in the table, how can i do?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
just a query!
« Reply #8 on: February 06, 2012, 04:36:54 pm »
Sorry, but I don't understand what you want to do.
Laurent Gomila - SFML developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
just a query!
« Reply #9 on: February 06, 2012, 05:38:12 pm »
Quote from: "Laurent"
Sorry, but I don't understand what you want to do.


soz!

i need to take a list of X names from my database with a SELECT sql input, how i can save in my program the X names? ( the number of the list can changed any time )

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
just a query!
« Reply #10 on: February 06, 2012, 08:36:18 pm »
You want the server to send the names to your application? The code that you showed will be ok, except that you should remove HTML formatting. Make it simple to parse for your application.
Laurent Gomila - SFML developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
just a query!
« Reply #11 on: February 08, 2012, 05:46:20 pm »
ok.. my problem is ->

i've only this code in a php page:

Code: [Select]
<?php
mysql_connect
&#40;'localhost','xxx','xxxxxx'&#41;;
mysql_select_db&#40;'xxxxx'&#41;;

$nick$_POST['N'&#93;;
$pass$_POST['P'&#93;;

$ris mysql_query&#40;"SELECT ID FROM User WHERE `NAME`='$nick' AND `PASS`='$pass'"&#41;;

if &#40;$ris!=NULL&#41;
&#123;
$stringa=  mysql_query&#40;"UPDATE Utente SET `ONLINE`='1' WHERE `ID`='$ris'"&#41;;
return $ris;
&
#125;
return -1;
?>




i need to "see" in my application the return values ( after conctacting the page ), how can i do?

soz for my misunderstandig

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
just a query!
« Reply #12 on: February 08, 2012, 07:15:32 pm »
The sf::Http::Response that you get in response to your request, contains the contents of the page that you generate on server side. So put whatever you need to respond in the page (with PHP code), and then retrieve it in your application with response.GetBody(). And then either display it directly, or parse it if you need to extract specific data.
Laurent Gomila - SFML developer

Haikarainen

  • Guest
just a query!
« Reply #13 on: February 09, 2012, 06:24:38 pm »
Querys via CLIENT -> HTTP -> PHP -> MySQL is one way to go, if you want more control over the querys and database, look into libmysql++ , wich is a C++ wrapper for libmysql c library.

Use it myself in a game, works purrrfectly. Be careful with storing the database access information though(user, pass etc). For my game, the client sends commands to a server, wich in turn queries a mysql db, wich is returned to the server, and then sent to the client.  that way nothing confidential is stored in the client, nor is anything confidental sent from or to the client itself.

 

anything