在mysql数据库上插入PHP不能使用PDO(带有预处理语句)

时间:2015-05-04 12:33:16

标签: php mysql pdo prepared-statement


我正在用DropzoneJS做一个简单的网站来上传文件,并在我的数据库中插入一些关于上传者的信息,文件类型等。
但问题是我在'upload_log'中没有看到任何内容文件上传后的表格 这是我的upload.php代码:

$ds = DIRECTORY_SEPARATOR;
    $foldername = "../common/uploads";

    if (!empty($_FILES)) {
        $fileupload = basename( $_FILES['file']['name']);
        $fileType = $_FILES['file']['type'];
        $fileSize = $_FILES['file']['size'];

        $tempFile = $_FILES['file']['tmp_name'];
        $targetPath = dirname( __FILE__ ) . $ds. $foldername . $ds;
        $targetFile =  $targetPath. $fileupload;
        move_uploaded_file($tempFile,$targetFile);
        $upload_info = "Filetype : <b>".$fileType."</b> <br>File size : <b>".$fileSize."</b><br>File name : <b> ".$fileupload."</b>";
        add_to_log($_SESSION['username'], 'upload', $upload_info);
    }

函数“add_to_log”:

function add_to_log($usr, $type, $info) { $servername = 'localhost'; $dbname = 'foo'; $username = 'root'; $password = 'foo'; try { $bdd = new PDO('mysql:host='.$servername.';dbname='.$dbname.'', $username, $password); } catch(Exception $e) { die('DB error'); } $req = $bdd->prepare('INSERT INTO upload_log(type, user, info) VALUES(:type, :user, :info)'); $req->execute(array( 'type' => $type, 'user' => $user, 'info' => $info )); }

0 个答案:

没有答案