--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Marcus Boerger <helly@php.net> |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "php.h"
+
+#if DBA_INIFILE
+#include "php_inifile.h"
+
+#include "libinifile/inifile.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define INIFILE_DATA \
+ inifile *dba = info->dbf
+
+#define INIFILE_GKEY \
+ key_type ini_key = inifile_key_split((char*)key) /* keylen not needed here */
+
+#define INIFILE_DONE \
+ inifile_key_free(&ini_key)
+
+DBA_OPEN_FUNC(inifile)
+{
+ info->dbf = inifile_alloc(info->fp, info->mode == DBA_READER, info->flags&DBA_PERSISTENT TSRMLS_CC);
+
+ return info->dbf ? SUCCESS : FAILURE;
+}
+
+DBA_CLOSE_FUNC(inifile)
+{
+ INIFILE_DATA;
+
+ inifile_free(dba, info->flags&DBA_PERSISTENT);
+}
+
+DBA_FETCH_FUNC(inifile)
+{
+ val_type ini_val;
+
+ INIFILE_DATA;
+ INIFILE_GKEY;
+
+ ini_val = inifile_fetch(dba, &ini_key, skip TSRMLS_CC);
+ *newlen = ini_val.value ? strlen(ini_val.value) : 0;
+ INIFILE_DONE;
+ return ini_val.value;
+}
+
+DBA_UPDATE_FUNC(inifile)
+{
+ val_type ini_val;
+ int res;
+
+ INIFILE_DATA;
+ INIFILE_GKEY;
+
+ ini_val.value = val;
+
+ if (mode == 1) {
+ res = inifile_append(dba, &ini_key, &ini_val TSRMLS_CC);
+ } else {
+ res = inifile_replace(dba, &ini_key, &ini_val TSRMLS_CC);
+ }
+ INIFILE_DONE;
+ switch(res) {
+ case -1:
+ php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
+ return FAILURE;
+ default:
+ case 0:
+ return SUCCESS;
+ case 1:
+ php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists");
+ return SUCCESS;
+ }
+}
+
+DBA_EXISTS_FUNC(inifile)
+{
+ val_type ini_val;
+
+ INIFILE_DATA;
+ INIFILE_GKEY;
+
+ ini_val = inifile_fetch(dba, &ini_key, 0 TSRMLS_CC);
+ INIFILE_DONE;
+ if (ini_val.value) {
+ inifile_val_free(&ini_val);
+ return SUCCESS;
+ }
+ return FAILURE;
+}
+
+DBA_DELETE_FUNC(inifile)
+{
+ INIFILE_DATA;
+ INIFILE_GKEY;
+ int res = inifile_delete(dba, &ini_key TSRMLS_CC);
+
+ INIFILE_DONE;
+ return (res == -1 ? FAILURE : SUCCESS);
+}
+
+DBA_FIRSTKEY_FUNC(inifile)
+{
+ INIFILE_DATA;
+
+ if (inifile_firstkey(dba TSRMLS_CC)) {
+ char *result = inifile_key_string(&dba->curr.key);
+ *newlen = strlen(result);
+ return result;
+ } else {
+ return NULL;
+ }
+}
+
+DBA_NEXTKEY_FUNC(inifile)
+{
+ INIFILE_DATA;
+
+ if (!dba->curr.key.group && !dba->curr.key.name) {
+ return NULL;
+ }
+
+ if (inifile_nextkey(dba TSRMLS_CC)) {
+ char *result = inifile_key_string(&dba->curr.key);
+ *newlen = strlen(result);
+ return result;
+ } else {
+ return NULL;
+ }
+}
+
+DBA_OPTIMIZE_FUNC(inifile)
+{
+ /* dummy */
+ return SUCCESS;
+}
+
+DBA_SYNC_FUNC(inifile)
+{
+ /* dummy */
+ return SUCCESS;
+}
+
+DBA_INFO_FUNC(inifile)
+{
+ return estrdup(inifile_version());
+}
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Marcus Boerger <helly@php.net> |
+ +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+
+#ifndef PHP_LIB_INIFILE_H
+#define PHP_LIB_INIFILE_H
+
+typedef struct {
+ char *group;
+ char *name;
+} key_type;
+
+typedef struct {
+ char *value;
+} val_type;
+
+typedef struct {
+ key_type key;
+ val_type val;
+ size_t pos;
+} line_type;
+
+typedef struct {
+ char *lockfn;
+ int lockfd;
+ php_stream *fp;
+ int fd;
+ int readonly;
+ line_type curr;
+ line_type next;
+} inifile;
+
+val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC);
+int inifile_firstkey(inifile *dba TSRMLS_DC);
+int inifile_nextkey(inifile *dba TSRMLS_DC);
+int inifile_delete(inifile *dba, const key_type *key TSRMLS_DC);
+int inifile_replace(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC);
+int inifile_append(inifile *dba, const key_type *key, const val_type *val TSRMLS_DC);
+char *inifile_version();
+
+key_type inifile_key_split(const char *group_name);
+char * inifile_key_string(const key_type *key);
+
+void inifile_key_free(key_type *key);
+void inifile_val_free(val_type *val);
+void inifile_line_free(line_type *ln);
+
+inifile * inifile_alloc(php_stream *fp, int readonly, int persistent TSRMLS_DC);
+void inifile_free(inifile *dba, int persistent);
+
+#endif
--- /dev/null
+#ifndef PHP_INIFILE_H
+#define PHP_INIFILE_H
+
+#if DBA_INIFILE
+
+#include "php_dba.h"
+
+DBA_FUNCS(inifile);
+
+#endif
+
+#endif
--- /dev/null
+--TEST--
+mysqli autocommit/commit/rollback
+--SKIPIF--
+<?php
+ include "connect.inc";
+ $link = mysqli_connect("localhost", $user, $passwd);
+ $result = mysqli_query($link, "SHOW VARIABLES LIKE 'have_innodb'");
+ $row = mysqli_fetch_row($result);
+ mysqli_free_result($result);
+ mysqli_close($link);
+
+ if ($row[1] == "DISABLED" || $row[1] == "NO") {
+ printf ("skip innodb support is not installed or enabled.");
+ }
+?>
+--FILE--
+<?php
+ include "connect.inc";
+ $link = mysqli_connect("localhost", $user, $passwd);
+
+ mysqli_select_db($link, "test");
+
+ mysqli_autocommit($link, TRUE);
+
+ mysqli_query($link,"DROP TABLE IF EXISTS ac_01");
+
+ mysqli_query($link,"CREATE TABLE ac_01(a int, b varchar(10)) type=InnoDB");
+
+ mysqli_query($link, "INSERT INTO ac_01 VALUES (1, 'foobar')");
+ mysqli_autocommit($link, FALSE);
+ mysqli_query($link, "DELETE FROM ac_01");
+ mysqli_query($link, "INSERT INTO ac_01 VALUES (2, 'egon')");
+
+ mysqli_rollback($link);
+
+ $result = mysqli_query($link, "SELECT * FROM ac_01");
+ $row = mysqli_fetch_row($result);
+ mysqli_free_result($result);
+
+ var_dump($row);
+
+ mysqli_query($link, "DELETE FROM ac_01");
+ mysqli_query($link, "INSERT INTO ac_01 VALUES (2, 'egon')");
+ mysqli_commit($link);
+
+ $result = mysqli_query($link, "SELECT * FROM ac_01");
+ $row = mysqli_fetch_row($result);
+ mysqli_free_result($result);
+
+ var_dump($row);
+
+ mysqli_close($link);
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ string(1) "1"
+ [1]=>
+ string(6) "foobar"
+}
+array(2) {
+ [0]=>
+ string(1) "2"
+ [1]=>
+ string(4) "egon"
+}
--- /dev/null
+--TEST--
+mysqli autocommit/commit/rollback with myisam
+--SKIPIF--
+<?php
+ include "connect.inc";
+ $link = mysqli_connect("localhost", $user, $passwd);
+ $result = mysqli_query($link, "SHOW VARIABLES LIKE 'have_innodb'");
+ $row = mysqli_fetch_row($result);
+ mysqli_free_result($result);
+ mysqli_close($link);
+
+ if ($row[1] == "NO") {
+ printf ("skip innodb support not installed.");
+ }
+?>
+--FILE--
+<?php
+ include "connect.inc";
+
+ $link = mysqli_connect("localhost", $user, $passwd);
+
+ mysqli_select_db($link, "test");
+
+ mysqli_autocommit($link, TRUE);
+
+ mysqli_query($link,"DROP TABLE IF EXISTS ac_01");
+
+ mysqli_query($link,"CREATE TABLE ac_01(a int, b varchar(10))");
+
+ mysqli_query($link, "INSERT INTO ac_01 VALUES (1, 'foobar')");
+ mysqli_autocommit($link, FALSE);
+
+ mysqli_query($link, "DELETE FROM ac_01");
+ mysqli_query($link, "INSERT INTO ac_01 VALUES (2, 'egon')");
+
+ mysqli_rollback($link);
+
+ $result = mysqli_query($link, "SELECT * FROM ac_01");
+ $row = mysqli_fetch_row($result);
+ mysqli_free_result($result);
+
+ var_dump($row);
+
+ mysqli_query($link, "DELETE FROM ac_01");
+ mysqli_query($link, "INSERT INTO ac_01 VALUES (2, 'egon')");
+ mysqli_commit($link);
+
+ $result = mysqli_query($link, "SELECT * FROM ac_01");
+ $row = mysqli_fetch_row($result);
+ mysqli_free_result($result);
+
+ var_dump($row);
+
+ mysqli_close($link);
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ string(1) "2"
+ [1]=>
+ string(4) "egon"
+}
+array(2) {
+ [0]=>
+ string(1) "2"
+ [1]=>
+ string(4) "egon"
+}
--- /dev/null
+--TEST--
+mysqli_stmt_affected_rows (delete)
+--FILE--
+<?php
+ include "connect.inc";
+
+ /*** test mysqli_connect 127.0.0.1 ***/
+ $link = mysqli_connect("localhost", $user, $passwd);
+
+ mysqli_select_db($link, "test");
+
+ mysqli_query($link, "DROP TABLE IF EXISTS test_affected");
+ mysqli_query($link, "CREATE TABLE test_affected (foo int)");
+
+ mysqli_query($link, "INSERT INTO test_affected VALUES (1),(2),(3),(4),(5)");
+
+ $stmt = mysqli_prepare($link, "DELETE FROM test_affected WHERE foo=?");
+ mysqli_bind_param($stmt, &$c1, MYSQLI_BIND_INT);
+
+ $c1 = 2;
+
+ mysqli_execute($stmt);
+ $x = mysqli_stmt_affected_rows($stmt);
+
+ mysqli_stmt_close($stmt);
+ var_dump($x==1);
+
+ mysqli_close($link);
+?>
+--EXPECT--
+bool(true)
--- /dev/null
+--TEST--
+non freed statement test
+--FILE--
+<?php
+ include "connect.inc";
+
+ /************************
+ * non freed stamement
+ ************************/
+ $link = mysqli_connect("localhost", $user, $passwd);
+
+ $stmt = mysqli_prepare($link, "SELECT CURRENT_USER()");
+ mysqli_execute($stmt);
+
+ mysqli_close($link);
+ printf("Ok\n");
+?>
+--EXPECT--
+Ok
--- /dev/null
+--TEST--
+not freed resultset
+--FILE--
+<?php
+ include "connect.inc";
+
+ /************************
+ * non freed resultset
+ ************************/
+ $link = mysqli_connect("localhost", $user, $passwd);
+
+ $result = mysqli_query($link, "SELECT CURRENT_USER()");
+ mysqli_close($link);
+ printf("Ok\n");
+
+?>
+--EXPECT--
+Ok
--- /dev/null
+--TEST--
+free resultset after close
+--FILE--
+<?php
+ include "connect.inc";
+
+ /************************
+ * free resultset after close
+ ************************/
+ $link = mysqli_connect("localhost", $user, $passwd);
+
+ $result1 = mysqli_query($link, "SELECT CURRENT_USER()");
+ mysqli_close($link);
+ mysqli_free_result($result1);
+ printf("Ok\n");
+?>
+--EXPECT--
+Ok
--- /dev/null
+--TEST--
+free nothing
+--FILE--
+<?php
+ include "connect.inc";
+
+ /************************
+ * don't free anything
+ ************************/
+ $link = mysqli_connect("localhost", $user, $passwd);
+
+ $result2 = mysqli_query($link, "SELECT CURRENT_USER()");
+ $stmt2 = mysqli_prepare($link, "SELECT CURRENT_USER()");
+ printf("Ok\n");
+?>
+--EXPECT--
+Ok
--- /dev/null
+--TEST--
+mysqli_prepare_result
+--FILE--
+<?php
+ include "connect.inc";
+
+ /*** test mysqli_connect 127.0.0.1 ***/
+ $link = mysqli_connect("localhost", $user, $passwd);
+
+ mysqli_select_db($link, "test");
+
+ mysqli_query($link,"DROP TABLE IF EXISTS test_store_result");
+ mysqli_query($link,"CREATE TABLE test_store_result (a int)");
+
+ mysqli_query($link, "INSERT INTO test_store_result VALUES (1),(2),(3)");
+
+ $stmt = mysqli_prepare($link, "SELECT * FROM test_store_result");
+ mysqli_execute($stmt);
+
+ /* this should produce an out of sync error */
+ if ($result = mysqli_query($link, "SELECT * FROM test_store_result")) {
+ mysqli_free_result($result);
+ printf ("Query ok\n");
+ }
+ mysqli_stmt_close($stmt);
+
+ $stmt = mysqli_prepare($link, "SELECT * FROM test_store_result");
+ mysqli_execute($stmt);
+ $result1 = mysqli_prepare_result($stmt);
+ mysqli_stmt_store_result($stmt);
+
+ printf ("Rows: %d\n", mysqli_stmt_affected_rows($stmt));
+
+ /* this should show an error, cause results are not buffered */
+ if ($result = mysqli_query($link, "SELECT * FROM test_store_result")) {
+ $row = mysqli_fetch_row($result);
+ mysqli_free_result($result);
+ }
+
+
+ var_dump($row);
+
+ mysqli_free_result($result1);
+ mysqli_stmt_close($stmt);
+ mysqli_close($link);
+?>
+--EXPECT--
+Rows: 3
+array(1) {
+ [0]=>
+ string(1) "1"
+}
--- /dev/null
+this module is experimental,
+its functions may change their names
+or move to extension all together
+so do not rely to much on them
+you have been warned!
--- /dev/null
+this module is experimental,
+its functions may change their names
+or move to extension all together
+so do not rely to much on them
+you have been warned!