2016-06-19 13 views
-1

私はPHPに新しいですし、私は...PDOなっ未定義の変数

<?php include 'connection.php'; 

function insertBlob($filePath, $mime) 
    { 
    $blob = fopen($filePath, 'rb'); 

    $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; 
    $stmt = $this->pdo->prepare($sql); 

    $stmt->bindParam(':mime', $mime); 
    $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); 

    return $stmt->execute(); 
} 

$strSQL-> insertBlob('C:\Users\Vishal\Desktop\house.png',"image/png"); 

if(mysqli_query($con, $strSQL)){ 
echo "Records added successfully."; 
} else{ 
echo "ERROR: Could not able to execute $strSQL. " . mysqli_error($con); 
} 

?> 
を見出しに言及した上記のように、私はこのエラーを取得してい を「BLOBデータ型を使用してデータベーステーブル内の画像をアップロードするPHPコードを」しようとしています

enter image description here

+0

あなたがこれを持っているところからblob.php' –

+0

'の19行目には何ですか? '$ strSQL->' –

+0

あなたは '$ strSQL = insertBlob(...)'を意味していますか? –

答えて

1

エラーは、変数$strSQLが未定義であると示しています。

$this->pdo->prepareあなたの機能にも意味がありません。

あなたはOOPを機能概念とミックスしています。

を更新しました

私はconnection.phpがクラスで、$strSQLは、そのクラスのインスタンスである、insertBlob()がないうちクラス定義内にある必要がありますと仮定します。

だから、新しいインスタンスを作成し、含ま下、

$strSQL = new WhatEverClass()

class MyConnection { 
    protected $pdo; 

    public function __construct() { 
     $this->pdo = ... 
    } 

    public function insertBlob($filePath, $mime) 
     { 
     $blob = fopen($filePath, 'rb'); 

     $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; 
     $stmt = $this->pdo->prepare($sql); 

     $stmt->bindParam(':mime', $mime); 
     $stmt->bindParam(':data', $blob, PDO::PARAM_LOB); 

     return $stmt->execute(); 
    } 

} 

    $strSQL = new MyConnection(); 
    $strSQL->insertBlob('C:\Users\Vishal\Desktop\house.png',"image/png");