Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过php将数据导入mysql_Php_Mysql - Fatal编程技术网

通过php将数据导入mysql

通过php将数据导入mysql,php,mysql,Php,Mysql,我已经用input type=“file”创建了一个html表单,现在我正在用php上传一个文本文件,文件正在移动到特定的文件夹中,因此成功连接到db后,一切都进展顺利。 但我想将该文件的数据导入mysql数据库,但该操作不起作用 剧本是: <?php $sql32="load data local infile 'C:\\wamp\\www\\my\\db_import\\$fname' into table contact_list (name, address, dob, rem

我已经用input type=“file”创建了一个html表单,现在我正在用php上传一个文本文件,文件正在移动到特定的文件夹中,因此成功连接到db后,一切都进展顺利。 但我想将该文件的数据导入mysql数据库,但该操作不起作用 剧本是:

<?php
$sql32="load data local infile 'C:\\wamp\\www\\my\\db_import\\$fname' 
into table  contact_list (name, address, dob, reminder, phone, mobile, email)" ;
$sql33=mysql_query($sql32) or die("could not upload data");
//here $fname is the file name
?>

您建立了连接吗?可能您的代码无法工作,因为您无法连接到数据库服务器。或者你的完整剧本。因为我的脚本是mysql\u query($con,$sqln)
对不起,如果我错了,我是新来的。

Poom

您确定
$fname
包含值吗?也许你可以试着重复一下

此外,我在处理字符串中的变量时总是遇到问题,请尝试将其用大括号括起来:

<?php
$sql32="load data local infile 'C:\\wamp\\www\\my\\db_import\\{$fname}' 
into table  contact_list (name, address, dob, reminder, phone, mobile, email)" ;
$sql33=mysql_query($sql32) or die("could not upload data");
//here $fname is the file name
?>

我想可能是您的文件路径错误。试一次我不确定

'C:\\wamp\\www\\my\\db_import\\$fname'
改为

'my/db_import/$fname'


检查

是的,正如我所说的,每种方法都很好,但那东西不起作用:(你所说的这种情况经常发生在你没有与数据库建立连接的时候。也许你忘记了包含连接文件?请检查一下,否则请在脚本中发布你正在使用的完整php脚本。我可以在这里看到我没有看到你在任何地方建立数据库连接。