Archive for January, 2010

Starting with SQLITE WITH PHP

First of all you need to make sure that the extension of sqlite is working through the settings in php.ini

Assuming its working, I will make it brief first create a file names create_database.php
And add the following to it


$db= new SQLiteDatabase("db.sqlite");
$db->query("
BEGIN;
CREATE TABLE users (id INTEGER UNSIGNED PRIMARY KEY,
name CHAR(255),
email CHAR(255));
INSERT INTO users (id,name,email) VALUES (NULL,'User1','user1@domain.com');
insert into users (id,name,email) values (NULL, 'user2','user2@lamis.com');
insert into users (id,name,email) values (NULL, 'user3','user3@lamis.com');
COMMIT;
");

This will create a new SQLiteDatabase and a table called users

now create another file call it test_result.php
and add the following to it

$db= new SQLiteDatabase("db.sqlite");
$result = $db->query("Select * from users");
echo "<br><br>++++++ POINTER WAY +++++++<br><br>";
while($result->valid())
{
print_r($result->current());
echo "<br>";
$result->next();
}
echo "<br><br>++++++ ASSOCIATIVE WITH FETCH+++++++<br><br>";
$result = $db->query("Select * from users");
while($row = $result->fetch(SQLITE_ASSOC))
{
print_r($row);
echo "<br>";
}
echo "<br><br>++++++ NUM WITH FETCH+++++++<br><br>";
$result = $db->query("Select * from users");
while($row = $result->fetch(SQLITE_NUM))
{
print_r($row);
echo "<br>";
}
echo "<br><br>++++++ FETCH ALL ++++++<br><br>";
$result = $db->query("Select * from users");
$rows= $result->fetchAll();
foreach($rows as $row)
{
print_r($row);
echo "<br>";
}
echo "<br><br>++++++ FETCH Object ++++++<br><br>";
$result = $db->query("Select * from users");
while($row = $result->fetchObject())
{
print_r($row);
echo "<br> you can call any like this \$row->id<br><br><br>";
}

using curl as post

First of all know this code work for something with no captcha

here how it goes

$url = "http://someurl.com";
$ch = curl_init();

The url is to specify the link for the post


// howmany parameter to post
curl_setopt($ch, CURLOPT_POST, 3);
// the parameter 'username' with its value 'johndoe'
curl_setopt($ch, CURLOPT_POSTFIELDS,"name=".$name."&username=".$username.."&email=".$email);
//TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result= curl_exec ($ch);
curl_close ($ch);

We can also add some settings which can be useful , for instance to ignore redirection in the url we can add

curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true);

Here is a link of the set of the things we can add

http://ca3.php.net/manual/en/function.curl-setopt.php

Return top

INFORMATION

Change this sentence and title from admin Theme option page.