Hi,

I'm currently trying to learn how to use php gtk2 to work with sqlite in stand alone application.

If i try to open it in browser all working.

But, its not working when i try to use php gtk and open it in stand alone application.
i've already enabled the php_sqlite.dll extensions in the php-cli.ini

Here is my code.

<?php
try
{
  //create or open the database
  //$database = new SQLiteDatabase('myDatabase.sqlite', 0666, $error);
  $database = new SQLiteDatabase('C:\php-gtk\demos\test.sqlite', 0666, $error);// it doesnt need any particular extension. can be .doc, .sqlite etc
  
  if ($database)
  {
	echo "connected";
  } else {
	die($error);
  }
}
catch(Exception $e)
{
  die($error);
}

//add User table to database
$query = 'CREATE TABLE t_users ' .
         '(Id Int, Name varchar(100))';
         
if(!$database->queryExec($query, $error))
{
  die($error);
}

//insert data into database
$query =
  'INSERT INTO t_users (Id, Name) ' .
  'VALUES (1, "John"); ' .
         
  'INSERT INTO t_users (Id, Name) ' .
  'VALUES (2, "Janice"); ' .
         
  'INSERT INTO t_users (Id, Name) ' .
  'VALUES (3, "Raja")';

if(!$database->queryExec($query, $error))
{
  die($error);
}

//read data from database
$query = "SELECT * FROM t_users";
if($result = $database->query($query, SQLITE_BOTH, $error))
{
  while($row = $result->fetch())
  {
    print("ID: {$row['Id']} <br />" .
          "Name: {$row['Name']} <br /><br />");
  }
}
else
{
  die($error);
}
?>

When i try to run the file, its give me

Fatal Error: Class 'SQLiteDatabase' not found in c:\\

Well I don't have any Ideas.

I took the php_sqlite.dll from my installation of php.

If anyone has any Ideas please help.

Thank you.

Do you have the database software installed on the machine the script is being run on? This can be a problem with php-gtk as when you transfer the program to another computer then the database will need transferring too so that both the database and the script are on the same computer. To be more detailed if for example you were trying to read a mssql database or even mysql database you will need to go to the mssql or mysql website, download their software and install it onto your computer then use something like phpmyadmin to add the database to the software. Then the php extension library will communicate with that sql software to retrieve data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.