mysqli bind_param error i believe, in SELECT FROM
Results 1 to 5 of 5

Thread: mysqli bind_param error i believe, in SELECT FROM

  1. #1
    Resident Kender kender's Avatar
    Join Date
    May 2004
    Location
    Great Lakes Region, USA
    Posts
    314

    mysqli bind_param error i believe, in SELECT FROM

    using this function it should take the query and check results against the type (integer, string, blob, decimal), if the result is correct type return it, if not then return error or nothing

    it executes correctly if type is correct, but if type is wrong it returns all results instead... not sure where it went wrong

    any help is always appreciated!
    thanks

    PHP Code:
    <?php
    $sql         
    "SELECT * FROM user WHERE last_name=? && first_name=?";
    $typeDef     = array("s","s");
    $data         = array("jones","jim");
    $query      sql_query($sql$typeDef$data);
    echo 
    '<pre>'print_r($query); echo '</pre>';

    function 
    sql_query($sql$typeDef$data) {
        
    $mysqli mysqli_con();

        
    $type ''$multiQuery '';
        foreach(
    $typeDef AS $val) { $type .= $val; }
        if(
    $stmt $mysqli->prepare($sql)) {
            if(
    count($data) == count($data1)) {
                
    $data = array($data);
                
    $multiQuery FALSE;
            } else {
                
    $multiQuery TRUE;
            }

            if(
    $type) {
                
    $bindParams = array();
                
    $bindParamsReferences = array();
                
    $bindParams array_pad($bindParams,(count($data,1)-count($data))/count($data), "");      
                foreach(
    $bindParams as $key => $value) {
                    
    $bindParamsReferences[$key] = &$bindParams[$key];
                }
                
    array_unshift($bindParamsReferences,$type);
                
    $bindParamsMethod = new ReflectionMethod('mysqli_stmt''bind_param');
                
    $bindParamsMethod->invokeArgs($stmt$bindParamsReferences);
            }

            
    $result = array();
            foreach(
    $data as $queryKey => $query) {
                foreach(
    $bindParams as $paramKey => $value) {
                    
    $bindParams[$paramKey] = $query[$paramKey];
                }
                
    $queryResult = array();
                if(
    mysqli_stmt_execute($stmt)) {
                    
    $resultMetaData mysqli_stmt_result_metadata($stmt);
                    if(
    $resultMetaData) {                                                   
                        
    $stmtRow = array();
                        
    $rowReferences = array();
                        while (
    $field mysqli_fetch_field($resultMetaData)) {
                            
    $rowReferences[] = &$stmtRow[$field->name];
                        }
                        
    mysqli_free_result($resultMetaData);
                        
    $bindResultMethod = new ReflectionMethod('mysqli_stmt''bind_result');
                        
    $bindResultMethod->invokeArgs($stmt$rowReferences);
                        while(
    mysqli_stmt_fetch($stmt)) {
                            
    $row = array();
                            foreach(
    $stmtRow as $key => $value) {
                                
    $row[$key] = $value;
                            }
                            
    $queryResult[] = $row;
                        }
                        
    mysqli_stmt_free_result($stmt);
                    } else {
                        
    $queryResult[] = mysqli_stmt_affected_rows($stmt);
                    }
                } else {
                    
    $queryResult[] = FALSE;
                }
                
    $result[$queryKey] = $queryResult;
            }
            
    mysqli_stmt_close($stmt);    
        } else {
            
    $result FALSE;
        }

        if(
    $multiQuery) {
            return 
    $result;
        } else {
            return 
    $result[0];
        }
    }
    ?>
    Now.

  2. #2
    Resident Kender kender's Avatar
    Join Date
    May 2004
    Location
    Great Lakes Region, USA
    Posts
    314
    I guess its bind_result error?

    still cant find where the error is though
    Now.

  3. #3
    Resident Kender kender's Avatar
    Join Date
    May 2004
    Location
    Great Lakes Region, USA
    Posts
    314
    I think the error is in this segment of code, but cant find a resolution
    PHP Code:
                        $bindResultMethod = new ReflectionMethod('mysqli_stmt''bind_result');
                        
    $bindResultMethod->invokeArgs($stmt$rowReferences);
                        while(
    mysqli_stmt_fetch($stmt)) {
                            
    $row = array();
                            foreach(
    $stmtRow as $key => $value) {
                                
    $row[$key] = $value;
                            }
                            
    $queryResult[] = $row;
                        } 
    Now.

  4. #4
    Resident Kender kender's Avatar
    Join Date
    May 2004
    Location
    Great Lakes Region, USA
    Posts
    314
    Nobody is able to shed any light on this?
    Now.

  5. #5
    Resident Kender kender's Avatar
    Join Date
    May 2004
    Location
    Great Lakes Region, USA
    Posts
    314
    Still stuck, but after looking deeper i think the problem is not where i said before but it is here
    PHP Code:
            if($type) {
                
    $bindParams = array();
                
    $bindParamsReferences = array();
                
    $bindParams array_pad($bindParams,(count($where_vals,1)-count($where_vals))/count($where_vals), "");      
                foreach(
    $bindParams as $key => $value) {
                    
    $bindParamsReferences[$key] = &$bindParams[$key];
                }
                
    array_unshift($bindParamsReferences,$type);
                
    $bindParamsMethod = new ReflectionMethod('mysqli_stmt''bind_param');
                
    $bindParamsMethod->invokeArgs($stmt$bindParamsReferences);
            } 
    Now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •