summaryrefslogtreecommitdiff
path: root/ext/mysqli/mysqli_warning.c
diff options
context:
space:
mode:
authorGeorg Richter <georg@php.net>2005-01-07 14:59:59 +0000
committerGeorg Richter <georg@php.net>2005-01-07 14:59:59 +0000
commit0b4c108bd78fff03e49b0be3934dd3c926fed589 (patch)
tree88ad589275108626383326a4151166524044f366 /ext/mysqli/mysqli_warning.c
parent05adbd51b47b90ebfcfeab7d97f4c2b4d28e4065 (diff)
downloadphp-git-0b4c108bd78fff03e49b0be3934dd3c926fed589.tar.gz
Added new classes:
mysqli_driver mysqli_warning mysqli_exception mysqli_sql_exception Improved embedded server support changed testsuite to work also with embedded server Made statement and resultset classes extendable minor fixes
Diffstat (limited to 'ext/mysqli/mysqli_warning.c')
-rw-r--r--ext/mysqli/mysqli_warning.c172
1 files changed, 172 insertions, 0 deletions
diff --git a/ext/mysqli/mysqli_warning.c b/ext/mysqli/mysqli_warning.c
new file mode 100644
index 0000000000..9114d7b493
--- /dev/null
+++ b/ext/mysqli/mysqli_warning.c
@@ -0,0 +1,172 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2004 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_0.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: Georg Richter <georg@php.net> |
+ +----------------------------------------------------------------------+
+
+*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <signal.h>
+
+#include "php.h"
+#include "php_ini.h"
+#include "ext/standard/info.h"
+#include "php_mysqli.h"
+
+/* {{{ void php_clear_warnings() */
+void php_clear_warnings(MYSQLI_WARNING *w)
+{
+ if (w->result) {
+ mysql_free_result(w->result);
+ }
+ efree(w);
+}
+/* }}} */
+
+/* {{{ void php_get_warnings(MYSQL *mysql) */
+MYSQLI_WARNING *php_get_warnings(MYSQL *mysql)
+{
+ MYSQLI_WARNING *w;
+ int cwarnings;
+
+ if (!(cwarnings = mysql_warning_count(mysql))) {
+ return NULL;
+ }
+
+ if (mysql_query(mysql, "SHOW WARNINGS")) {
+ return NULL;
+ }
+
+ if (!(w = (MYSQLI_WARNING *)ecalloc(sizeof(MYSQLI_WARNING), 1))) {
+ return NULL;
+ }
+
+ w->warning_count = cwarnings;
+ w->result = mysql_store_result(mysql);
+ if (!(w->row = mysql_fetch_row(w->result))) {
+ mysql_free_result(w->result);
+ efree(w);
+ return NULL;
+ }
+
+ return w;
+}
+/* }}} */
+
+/* {{{ mysqli_warning::__construct */
+ZEND_FUNCTION(mysqli_warning_construct)
+{
+ MYSQL *mysql = NULL;
+ MYSQLI_WARNING *w;
+ MYSQLI_RESOURCE *mysqli_resource;
+ mysqli_object *obj;
+
+ if (!getThis()) {
+ RETURN_FALSE;
+ }
+
+ obj = (mysqli_object *)zend_objects_get_address(getThis() TSRMLS_CC);
+
+ if (obj->zo.ce == mysqli_link_class_entry) {
+ mysql = (MYSQL *)((MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->mysql;
+ } else if (obj->zo.ce == mysqli_stmt_class_entry) {
+ mysql = (MYSQL *)((MY_STMT *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr)->stmt->mysql;
+ }
+
+ if ((w = php_get_warnings(mysql))) {
+ mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
+ mysqli_resource->ptr = (void *)w;
+ obj->valid = 1;
+
+ MYSQLI_RETURN_RESOURCE(mysqli_resource, mysqli_warning_class_entry);
+ } else {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ bool mysqli_warning::next */
+ZEND_FUNCTION(mysqli_warning_next) {
+ MYSQLI_WARNING *w;
+ zval *mysql_warning;
+ mysqli_object *obj = (mysqli_object *)zend_objects_get_address(getThis() TSRMLS_CC);
+
+ if (obj->valid) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &mysql_warning, mysqli_warning_class_entry) == FAILURE) {
+ return;
+ }
+
+ MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, &mysql_warning, "mysqli_warning");
+
+ if (w->warning_count && (w->row = mysql_fetch_row(w->result))) {
+ RETURN_TRUE;
+ }
+ }
+ RETURN_FALSE;
+}
+/* }}} */
+
+/* {{{ property mysqli_warning_error */
+int mysqli_warning_error(mysqli_object *obj, zval **retval TSRMLS_DC)
+{
+ MYSQLI_WARNING *w;
+
+ ALLOC_ZVAL(*retval);
+ w = obj->valid ? (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr : NULL;
+
+ if (w && w->row && w->row[2]) {
+ ZVAL_STRING(*retval, w->row[2], 1);
+ } else {
+ ZVAL_NULL(*retval);
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ property mysqli_warning_error */
+int mysqli_warning_errno(mysqli_object *obj, zval **retval TSRMLS_DC)
+{
+ MYSQLI_WARNING *w;
+
+ ALLOC_ZVAL(*retval);
+ w = obj->valid ? (MYSQLI_WARNING *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr : NULL;
+
+ if (w && w->row && w->row[1]) {
+ ZVAL_LONG(*retval, atoi(w->row[1]));
+ } else {
+ ZVAL_NULL(*retval);
+ }
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ mysqli_warning_methods[]
+ */
+function_entry mysqli_warning_methods[] = {
+ PHP_FALIAS(__construct,mysqli_warning_construct, NULL)
+ PHP_FALIAS(next,mysqli_warning_next,NULL)
+ {NULL, NULL, NULL}
+};
+/* }}} */
+
+
+mysqli_property_entry mysqli_warning_property_entries[] = {
+ {"error", mysqli_warning_error, NULL},
+ {"errno", mysqli_warning_errno, NULL},
+ {NULL, NULL, NULL}
+};