从DB读取时遇到问题

时间:2011-01-10 14:20:06

标签: php android database sqlite

我正在编写一个赋值,我需要弄清楚如何读取使用我编写的PHP脚本创建的数据库文件。我是Android平台的新手,在过去的一周里花了几个小时跟着教程,但我仍在苦苦挣扎。我需要从数据库中读取并在屏幕上的UI中显示。我敢肯定它不会太难,但我正在某个地方滑倒!任何帮助都会得到真正的赞赏。

当前的PHP脚本 -

<html>
<body>

<?php
//Connect to college database
$studentnum = "SY090627";
$con = mysql_connect("localhost","******","*******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("computin_mobile", $con);
//Select all needed student data
//Must include custext from student table to retrive students college username
$result = mysql_query("SELECT * FROM students, time WHERE (time.CusText5='$studentnum' AND students.StuRef ='$studentnum') ORDER BY time.DayNum ASC, time.StartTime");



$newLine = "\n";

try
{
  //create the database
  $database = new SQLiteDatabase('myDatabase.sqlite', 0666, $error);
}
catch(Exception $e)
{
  die($error);
}

//add Lesson table to database
$query = 'CREATE TABLE Lessons ' .
         '(Day TEXT, StartTime TEXT, EndTime TEXT, Teacher TEXT, Description TEXT, Room TEXT)';

if(!$database->queryExec($query, $error))
{
  die($error);
}
while($row = mysql_fetch_array($result))
  {
//insert data into database
$dayr = $row['Day'];
$query =
  'INSERT INTO Lessons (Day, StartTime, EndTime, Teacher, Description, Room) ' .
  'VALUES ("'.$row['Day'].'", "'.$row['StartTime'].'", "'.$row['EndTime'].'", "'.$row['Teacher'].'", "'.$row['Description'].'", "'.$row['Room'].'")';

if(!$database->queryExec($query, $error))
{
  die($error);
}
  }
//read data from database
$query = "SELECT * FROM Lessons";
if($result = $database->query($query, SQLITE_BOTH, $error))
{
  while($row = $result->fetch())
  {
    print("Day: {$row['Day']} <br />" .
          "Start Time: {$row['StartTime']} <br />".
          "End Time: {$row['EndTime']} <br />".
          "Teacher: {$row['Teacher']} <br />".
          "Description {$row['Description']} <br />".
          "Room: {$row['Room']} <br /><br />");

  }
}
else
{
  die($error);
}
?> 

</body>
</html> 

1 个答案:

答案 0 :(得分:0)

Step1:使用php生成mysql到xml 有关该推荐,请参阅这些网址thisthisthis   Step2:有一次,您创建了XML文件,然后使用SAX解析器解析该xml文件。对于这些,请参阅此url

相关问题