PHP文件删除MySQL表而不是添加它

时间:2015-05-19 17:07:13

标签: php mysql

我最近将服务器升级到PHP5.4,因为PHP5.3已被弃用。这导致我的func.php文件删除我们的mySQL表而不是添加它们的问题。它曾经抓取三个.txt文件(如下所示)并将数据插入我们的mySQL数据库。我不确定为什么会发生这种情况,因为脚本在更新之前正在运行。任何有关解决此问题的建议或建议都将不胜感激,谢谢!

enter image description here

PHP

<?php
header('Content-Type: application/json; charset=UTF-8');
$argv = $_SERVER['argv'];
$totalArgv = count($argv);
$dsn = 'mysql:dbname=******;host=127.0.0.1';
$dsn_training = 'mysql:dbname=******;host=127.0.0.1';
$user = '******';
$password = '*****';
function is_ajax() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
}

function move_files(){
try {
    move_file('sfinder/StoreList.txt');
    move_file('sfinder/StoreProductIndex.txt');
    move_file('sfinder/StoreTypeIndex.txt');
    move_file('training/TrainingCustomerList.txt');
}
catch(Exception $e){
    die_with_error($e->getMessage());
}

//sleep(1);
//Return JSON
$return["json"] = json_encode($return);
//echo json_encode($return);
}

function empty_table($dbconnection, $tablename){
try{
    $sql = "TRUNCATE TABLE " . $tablename;
    $sth = $dbconnection->prepare($sql);
    //$sth->bindParam(':tablename', $tablename, PDO::PARAM_STR);

    // The row is actually inserted here
    $sth->execute();
    //echo " [+]Table '" . $tablename . "' has been emptied.<br>";
    $sth->closeCursor();
}
catch(PDOException $e) {  
    die_with_error($e->getMessage()); 
}
}

function copy_additional($dbconn, $tablename){
try{
    $sql = "INSERT INTO stores
        (csid, store_name, address1, address2, city, state, zip, phone, fax, website, coord_lat, coord_long, x_axis, y_axis, z_axis)
        SELECT csid, store_name, address1, address2, city, state, zip, phone, fax, website, coord_lat, coord_long, x_axis, y_axis, z_axis
        FROM " . $tablename . ";";
    $sth = $dbconn->prepare($sql);

    // Execute SQL command
    $sth->execute();
    //echo " [+]CSV File for '" . $tablename . "' Table Imported.<br>";
    $sth->closeCursor();
}
catch(PDOException $e) {  
    die_with_error($e->getMessage()); 
}

0 个答案:

没有答案