77;20202;0ccatbody - よくきたWiki

Loading ...


APC
SQLite
tidy
mailparse
apd
bcompiler
Xdebug

http://cvs.php.met/)

gdchart
namazu

*1


phpize

make
make install

pear install SQLite

*2

<?php
if (!extension_loaded("sqlite")) {
        dl("sqlite.so");
}

debug_zval_dump(sqlite_libversion());
debug_zval_dump(sqlite_libencoding());

$s = sqlite_open("weztest.sqlite", 0666, $err);

debug_zval_dump($err);
debug_zval_dump($s);

$r = sqlite_query("create table foo (a INTEGER PRIMARY KEY, b INTEGER )", $s);
debug_zval_dump(sqlite_last_error($s));
debug_zval_dump(sqlite_error_string(sqlite_last_error($s)));

$r = sqlite_query("select *, php('md5', sql) as o from sqlite_master", $s);
debug_zval_dump($r);
debug_zval_dump(sqlite_num_rows($r));
debug_zval_dump(sqlite_num_fields($r));

for ($j = 0; $j < sqlite_num_fields($r); $j++) {
        echo "Field $j is " . sqlite_field_name($r, $j) . "\n";
}

while ($row = sqlite_fetch_array($r, SQLITE_ASSOC)) {
        print_r($row);
}

sqlite_close($s);

?>
php -Cq sqlite.php
string(5) "2.8.3" refcount(1)
string(7) "iso8859" refcount(1)
NULL refcount(2)
resource(4) of type (sqlite database) refcount(2)
long(0) refcount(1)
string(12) "not an error" refcount(1)
resource(6) of type (sqlite result) refcount(2)
long(1) refcount(1)
long(6) refcount(1)
Field 0 is type
Field 1 is name
Field 2 is tbl_name
Field 3 is rootpage
Field 4 is sql
Field 5 is o
Array
(
    [type] => table
    [name] => foo
    [tbl_name] => foo
    [rootpage] => 3
    [sql] => create table foo (a INTEGER PRIMARY KEY, b INTEGER )
    [o] => 2f5a980ca57765ddef1a9434c15d755f
)

** This file contains an SQLite 2.1 database **
Ktable
create table foo (a INTEGER PRIMARY KEY, b INTEGER )

pear upgrade DB

define( "DB_FILE", dirname( __FILE__)."/contact.sqlite");


if ( extension_loaded( 'sqlite') != TRUE) {
  if ( dl( 'sqlite.so') != true) {

    exit;
  }
}

class myDB extends DB {

  function connect() {
    $dsn = array (
        'phptype'=>"sqlite",
        'database'=>DB_FILE,
        'mode'=> 0666
    );
    return parent::connect( $dsn);
  }
}

<?php

require_once "mydb.inc";

if ( file_exists( DB_FILE) != TRUE || filesize( DB_FILE) == 0) {
  $db = myDB::connect();
  if (DB::isError($db) != TRUE) {
    $res =$db->query( "CREATE TABLE contact_info ( c_name varchar(100), c_mail varchar(50), c_text varchar(255));");
    $db->disconnect();
    if (DB::isError($db)) {
      unlink( DB_FILE);

      exit;
    }  
  }
}

php -Cq create_db.php
chmod 666 contact.sqlite

function sendForm( $values) {
  $db = myDB::connect();
  if (DB::isError($db) != TRUE) {
    $c_name = $db->quote( $values[ "name"]);
    $c_mail = $db->quote( $values[ "mail"]);
    $c_text = $db->quote( $values[ "text"]);
    $res = $db->query( "INSERT INTO contact_info VALUES($c_name,$c_mail,$c_text);");
    if (DB::isError($res)) {

      exit;
    }
    $db->disconnect();
  }

}

<?php

require_once "mydb.php";

$db = myDB::connect();
if (DB::isError($db)) {

  exit;
}

$res = $db->query( "SELECT c_name, c_mail, c_text FROM contact_info");
if (DB::isError($db)) {

  exit;
}
print <<<EOD
<table border="1">
<thead>

</thead>
<tbody>
EOD;

while ( $row = $res->fetchRow( DB_FETCHMODE_ASSOC)) {
  foreach ( array( "c_name", "c_mail", "c_text") as $name) {
    $$name = nl2br( htmlspecialchars( $row[ $name]));
  }
  print " <tr><td>$c_name</td><td>$c_mail</td><td>$c_text</td></tr>\n";
}

print <<<EOD
</tbody>
</table>

EOD;

$db->disconnect();

?>

Writing



*1
*2
リロード   新規 編集 凍結 差分 添付 複製 改名   トップ 一覧 検索 最終更新 バックアップ   ヘルプ   最終更新のRSS
最終修正日時: Mon, 02 May 2005 11:52:00 JST (4554d)
文字数(HTML): 3716
文字数(Wiki): 8783
人気ブログランキング - よくきた wiki