function pub_column_exists( mysqli $conn, string $table, string $column ): bool { $t = str_replace('`', '``', $table); $c = mysqli_real_escape_string($conn, $column); $q = mysqli_query( $conn, "SHOW COLUMNS FROM `{$t}` LIKE '{$c}'" ); if (!$q) { return false; } $exists = mysqli_num_rows($q) > 0; mysqli_free_result($q); return $exists; } /* |-------------------------------------------------------------------------- | mysqlnd-safe prepared statement helper |-------------------------------------------------------------------------- */ function pub_stmt_fetch_assoc( mysqli_stmt $stmt ): ?array { if ( function_exists( 'mysqli_stmt_get_result' ) ) { $result = mysqli_stmt_get_result( $stmt ); if (!$result) { return null; } $row = mysqli_fetch_assoc( $result ) ?: null; mysqli_free_result( $result ); return $row; } $meta = mysqli_stmt_result_metadata( $stmt ); if (!$meta) { return null; } $fields = mysqli_fetch_fields( $meta ); mysqli_free_result( $meta ); if (!$fields) { return null; } $values = []; $refs = []; foreach ($fields as $field) { $name = (string)$field->name; $values[$name] = null; $refs[] =& $values[$name]; } if ( !mysqli_stmt_bind_result( $stmt, ...$refs ) ) { return null; } if ( mysqli_stmt_fetch( $stmt ) !== true ) { return null; } $row = []; foreach ( $values as $key => $value ) { $row[$key] = $value; } return $row; }