Witam próbuje sobie zrobić prosty program z połączoną bazą danych, wyswietlenie zawartości jednej tabeli, serwer SQL odpalam lokalnie na XAMP, zaś skrypt php wrzuciłem na darmowy hosting,
PHP wygląda tak:
<?php
include 'dbsettings.php';
$con = mysql_connect(127.0.0.1:3306,$user,$pass);
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tutorials", $con);
$result = mysql_query("SELECT * FROM `scores`");
while($row = mysql_fetch_array($result))
{
echo $row['user'] . "-" . $row['score'] . "@";
}
mysql_close($con);
?>
zaś kod programu:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using TutorialDataBase.Resources;
using System.IO;
namespace TutorialDataBase
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void buttonSprawdz_Click(object sender, RoutedEventArgs e)
{
sprawdzBlock.Text = "Checking for scores...";
var webClient = new WebClient();
webClient.OpenReadAsync(new Uri("http://amgmeble.cba.pl/highscore.php?" + DateTime.Now));
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(getscores_OpenReadCompleted);
}
private void getscores_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
try
{
using (var reader = new StreamReader(e.Result))
{
string[] response = reader.ReadToEnd().Split('@');
int totalsplits = response.Length;
int i = 0;
scoreListBox.Items.Clear();
while(i<totalsplits)
{
string[] splitdata = response[i].Split('~');
scoreListBox.Items.Add(splitdata[0].ToString() + " = " + splitdata[1].ToString());
i++;
}
sprawdzBlock.Text = "Score have ben gathered...";
}
}
catch
{
sprawdzBlock.Text = "Score failed to collect...";
}
}
}
}
baza danych zawiera jedna tabele z dwoma kolumnami user, score,
chce wyświetlić zawartość tej tabeli ale list boxie to tylko jakies dziwne <!-- =
ktoś ma pomysł co może być nie tak ?