简体   繁体   English

使用wamp连接本地数据库的php

[英]php connection to the local database with wamp

As part of my internship, I try to change the dynamic website of the company.作为实习的一部分,我尝试改变公司的动态网站。 To do this, I installed Wamp and I transferred locally, the website of the company with filezilla I exported three databases in the hebergeur site.为此,我安装了 Wamp 并在本地传输了带有 filezilla 的公司网站,我在 hebergeur 站点中导出了三个数据库。 I imported these databases give in phpMyadmin.我在 phpMyadmin 中导入了这些数据库。

When I try to work locally, I displays errors that I can not interpret (please see the next picture).当我尝试在本地工作时,我显示了我无法解释的错误(请参见下一张图片)。

[a link] https://docs.google.com/file/d/0B6PyFANH4lYqNC1USm9oOEhEMGs/edit?usp=sharing [链接] https://docs.google.com/file/d/0B6PyFANH4lYqNC1USm9oOEhEMGs/edit?usp=sharing

In (1) is normally a dropdown list that displays the zip code of cities.在(1)中通常是一个下拉列表,显示城市的邮政编码。 In local it shows me : (!) Notice: Undefined index: dep in D:\\wamp\\www\\site_choix_funeraire\\points-vente.php on line 282 Call Stack #TimeMemoryFuction在本地它显示我:(!)注意:未定义的索引:dep in D:\\wamp\\www\\site_choix_funeraire\\points-vente.php on line 282 Call Stack #TimeMemoryFuction

When I click on the map, for example, the postal code 76 (see the rag (2) in the first photo) it shows me the next photo例如,当我点击地图时,邮政编码 76(请参阅第一张照片中的抹布 (2))它会显示下一张照片

[a link] https://docs.google.com/file/d/0B6PyFANH4lYqZWFZQTItdmhRS0E/edit?usp=sharing [链接] https://docs.google.com/file/d/0B6PyFANH4lYqZWFZQTItdmhRS0E/edit?usp=sharing

I think the site does not read from the database.我认为该站点不会从数据库中读取。 When I imported the database (the .Sql) in phpMyAdmin, it is necessary to add another setting to the site to tell him to point to the database or is this done systematically?当我在phpMyAdmin中导入数据库(.Sql)时,需要在站点中添加另一个设置来告诉他指向数据库还是系统地完成?

What do you think about the problem and the display ?您如何看待问题和显示? Thank you in advance先感谢您

The database that you have imported must have the same name as the project.您导入的数据库必须与项目同名。

I don't know what IDE you are working on,but on the run properties you must define from where the project you will.我不知道您在使用什么 IDE,但是在运行属性上,您必须从项目的位置进行定义。

It must run from the wamp htdocs folder (inside it you must copy the project folder).它必须从 wamp htdocs 文件夹运行(您必须在其中复制项目文件夹)。

Also at the preferences set the ports to default.同样在首选项中将端口设置为默认值。

Looks like you're trying to connect to a database host that doesn't exist (that's what the "getaddrinfo failed" part means).看起来您正在尝试连接到不存在的数据库主机(这就是“getaddrinfo failed”部分的含义)。

The documentation for the mysql_connect function is here , and indicates that the first argument is the host name of the server running the database. mysql_connect 函数的文档在这里,并指出第一个参数是运行数据库的服务器的主机名。 Since you're using a WAMP stack, you'll want to make sure that says "localhost" (make sure to change it back when you deploy).由于您使用的是 WAMP 堆栈,因此您需要确保显示“localhost”(确保在部署时将其改回)。

For example:例如:

mysql_connect("localhost", "my_username", "my_password");

I will also note that it is unlikely that your database dumps also copied the database users that are being used on the live site, so you will either have to create them on your local machine or use a different database account that does exist (again, remember to change it back when you deploy).我还要指出,您的数据库转储不太可能也复制了在实时站点上使用的数据库用户,因此您要么必须在本地计算机上创建它们,要么使用确实存在的其他数据库帐户(再次,记得在部署的时候改回来)。

Try this to connect to the localhost server.试试这个连接到本地主机服务器。

<?php
$connect = mysql_connect("localhost:3306", "root", "mypassword");
echo($connect);?>

Try this out试试这个

<?php
$connect = mysqli_connect("localhost:3306", "root", "password");
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM