mysql表导入不起作用?

时间:2016-07-20 08:25:45

标签: php mysql database import export

我将数据库表导出到.sql文件中。 之后我重新安装了WAMP,我创建了一个新数据库并导入了表。

导入的表不起作用,我应该检查mysql中的哪些设置成功迁移?

这个代码

if (isset($_POST['send'] )  )
{

$servername = "****";
$username = "****";
$password = "****";
$dbname = "****";

$conn = new mysqli($servername, $username, $password,       $dbname);
if ($conn->connect_error) { die("Connection failed: " . $conn    >connect_error);}



$sql = "INSERT INTO $tabel (fname, lname, strnu, poco, place, pro_reg,    country, email, tele, mobi, citizen, pport_id, birthday, cl_nr, sxmf) VALUES 
                     ('$fname' , '$lname' , '$strnu' , '$poco' , '$place' , '$pro_reg' , '$country' , '$email' , '$tele' , '$mobi' , '$citizen' , '$pport_id' , '$birthday' , '$cl_nr' , '$sxmf')" ; 
                        if ($conn->query($sql) === TRUE)

                            {  echo' Thank you for completing this form'; 
                                var_dump($fname);                               

                            }   else { 

                            echo "Error: " . $sql  ;
                            $conn->error;

                            }

$hi_val = mysqli_insert_id($conn);                      
// data fetch
$sql2 = "SELECT id, fname, lname, strnu, poco, place, pro_reg, country,   email, tele, mobi, citizen, pport_id, birthday, cl_nr, sxmf FROM $tabel WHERE id  = $hi_val";
$result = $conn->query($sql2);


// output data of each row
while($row = $result->fetch_assoc()) {

    //var_dump($hi_val);

  //  echo 'id: ' . $row["id"];


    $fname = $row["fname"];
  // etc
} 
}

这是我制作的表格:

-- phpMyAdmin SQL Dump
-- version 4.5.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generated: 19 jul 2016 at 07:42
-- Server version: 5.7.11
-- PHP-version: 5.6.19

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `dbase_name`
--

  -- --------------------------------------------------------

--
-- Tabelstructure for table `user`
--

CREATE TABLE `user` (
`fname` text NOT NULL,
`lname` text NOT NULL,
`strnu` varchar(45) NOT NULL,
`poco` varchar(15) NOT NULL,
`place` text NOT NULL,
`pro_reg` varchar(30) NOT NULL,
`country` text NOT NULL,
`email` varchar(40) NOT NULL,
`tele` varchar(20) NOT NULL,
`mobi` varchar(20) NOT NULL,
`citizen` text NOT NULL,
 `pport_id` varchar(25) NOT NULL,
`birthday` varchar(15) NOT NULL,
`id` tinyint(3) NOT NULL,
`cl_num` varchar(25) NOT NULL,
`sxmf` text NOT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Index exported tables
--

--
-- Index for table `user`
--
ALTER TABLE `user`
 ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT exported table
--

--
-- AUTO_INCREMENT table `user`
--
ALTER TABLE `user`
 MODIFY `id` tinyint(3) NOT NULL AUTO_INCREMENT;
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

2 个答案:

答案 0 :(得分:0)

insert和select语句引用

cl_nr

名为

cl_num
表中的

答案 1 :(得分:0)

我首先要检查您的用户名,密码和表名是否准确。

在命令行中启动MySQL。

SELECT * FROM mysql.user;

重设密码

UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';

别忘了开始停止mysql并重启它并记住你的新用户名。

这是this post

确保您的PHP文件包含这些更新的用户名和密码,并确保重启后您的WAMP服务器图标为绿色。

让我知道它是怎么回事,否则就丢桌并重新上传。古德勒克!