数据不存储

时间:2014-05-11 05:07:47

标签: php mysql

这是我的连接类

class Connection {

    public function query($sql){
        mysql_connect('localhost','root','') or die("Connection error ". mysql_error());
        mysql_select_db('liontours') or die("Database error ". mysql_error());
        $results = mysql_query($sql);
        $last_inserted_id = mysql_insert_id();      
        return array('results'=>$results, 'last_id'=>$last_inserted_id);
        }


    }

这是我的模特

    public function V_reg($v_no, $dl_no, $owner, $o_name, $o_nic, $i_date, $ex_date, $p_report, $nic, $s_name, $f_name, $initials, $dob, $stat, $v_type) {


        $sql = "INSERT INTO `vehicledetails`(`vehicle_no`, `owner`, `owner_name`, `owner_nic`, `insured_date`, `ex_date`, `police_report`,`type`)
                VALUES ('$v_no','$owner','$o_name','$o_nic','$i_date','$ex_date','$p_report','$v_type')";

        $conn = new Connection();
        //vehicle id of last inserted record
        $vehicle_id = mysql_insert_id();
        $results = $conn->query($sql);
        $last_vehicle_record_id = $results['last_id'];
        $fk_key = $last_vehicle_record_id;
        //checking the first table insert successful if so do the second insert else must define counter measure in else part 
        if ($fk_key !== 0) {
                $sql1 = "INSERT INTO driverdetails (id, vehicle_id, nic,sir_name,first_name,dlNo,initials,dob,status )
                VALUES ('null', '$fk_key', '$nic','$s_name','$f_name','$dl_no', '$initials','$dob','$stat')";
                $results = $conn->query($sql1);

        }else{
            die('transaction failed').mysql_error();
        }

        return $results;
    }

}

我不知道这个编码有什么问题,但它没有传递数据,因为它说事务失败并且没有给出错误。只是文字可以告诉我这个编码有什么问题?如果没有编码错误,我的数据库有问题吗?

0 个答案:

没有答案