简体   繁体   中英

PHP convert base64 image string to blob for MySQL

I have the base64 string of an image in PHP, for example:

$imgStr =  'data:image/png;base64,E0LdjA==';

I have a MySQL table with 2 fields id(varchar) and img(blob) . i have a stored procedure that inserts these values and is exceuted from PHP.

i used base64_decode($imgStr) to convert the image to blob, the procedures executes but the value of blob in the Database is empty.

here is my PHP function for the execution:

function test($id,$img){
        if (connect()){
            global $conn;
            $query = $conn->prepare("CALL prctest(?,?,@rtn)");
            $blob = base64_decode($img); 
            $query->bind_param('sb',$id,$blob); 
            $query->execute();
            $result = $conn->query("SELECT @rtn as rtn");
            $row = $result->fetch_assoc();
            echo  $row['rtn'];
            $result->free();
            close();
        }
        else{
            echo "connection error!";
        }
    }

i cant figure out what wrong!

I have the base64 string of an image in PHP, for example:

$imgStr =  'data:image/png;base64,E0LdjA==';

I have a MySQL table with 2 fields id(varchar) and img(blob) . i have a stored procedure that inserts these values and is exceuted from PHP.

i used base64_decode($imgStr) to convert the image to blob, the procedures executes but the value of blob in the Database is empty.

here is my PHP function for the execution:

function test($id,$img){
        if (connect()){
            global $conn;
            $query = $conn->prepare("CALL prctest(?,?,@rtn)");
            $blob = base64_decode($img); 
            $query->bind_param('sb',$id,$blob); 
            $query->execute();
            $result = $conn->query("SELECT @rtn as rtn");
            $row = $result->fetch_assoc();
            echo  $row['rtn'];
            $result->free();
            close();
        }
        else{
            echo "connection error!";
        }
    }

i cant figure out what wrong!

I have the base64 string of an image in PHP, for example:

$imgStr =  'data:image/png;base64,E0LdjA==';

I have a MySQL table with 2 fields id(varchar) and img(blob) . i have a stored procedure that inserts these values and is exceuted from PHP.

i used base64_decode($imgStr) to convert the image to blob, the procedures executes but the value of blob in the Database is empty.

here is my PHP function for the execution:

function test($id,$img){
        if (connect()){
            global $conn;
            $query = $conn->prepare("CALL prctest(?,?,@rtn)");
            $blob = base64_decode($img); 
            $query->bind_param('sb',$id,$blob); 
            $query->execute();
            $result = $conn->query("SELECT @rtn as rtn");
            $row = $result->fetch_assoc();
            echo  $row['rtn'];
            $result->free();
            close();
        }
        else{
            echo "connection error!";
        }
    }

i cant figure out what wrong!

I have the base64 string of an image in PHP, for example:

$imgStr =  'data:image/png;base64,E0LdjA==';

I have a MySQL table with 2 fields id(varchar) and img(blob) . i have a stored procedure that inserts these values and is exceuted from PHP.

i used base64_decode($imgStr) to convert the image to blob, the procedures executes but the value of blob in the Database is empty.

here is my PHP function for the execution:

function test($id,$img){
        if (connect()){
            global $conn;
            $query = $conn->prepare("CALL prctest(?,?,@rtn)");
            $blob = base64_decode($img); 
            $query->bind_param('sb',$id,$blob); 
            $query->execute();
            $result = $conn->query("SELECT @rtn as rtn");
            $row = $result->fetch_assoc();
            echo  $row['rtn'];
            $result->free();
            close();
        }
        else{
            echo "connection error!";
        }
    }

i cant figure out what wrong!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM