[英]mysql_connect not being recognized as a function/PHP not connecting to MySQL in Apache
A little background for context: I'm pretty new to programming and such, and I have been trying for the past few months to set up a development environment on my laptop so I can practice with some basic stuff--PHP, Javascript, MySQL, possibly Python in the near future--and I have spent the past few months, off-and-on, trying to set up this environment with mixed results. 有关背景的一些背景知识:我对编程等还很陌生,并且过去几个月来我一直在尝试在笔记本电脑上设置开发环境,以便我可以练习一些基本知识-PHP,Javascript,MySQL ,可能是在不久的将来使用Python),而我花了过去几个月的时间,不停地尝试,以不同的结果来设置这种环境。 I installed Apache 2.2, PHP 5.4.30, and MySQL 5.6 and have been tinkering with it the past couple nights trying to figure out on my own why a few things aren't working.
我安装了Apache 2.2,PHP 5.4.30和MySQL 5.6,并且在过去的两晚里一直在修补它,试图自己弄清为什么有些东西不起作用。
Right now my issue is this: 现在我的问题是这样的:
I'm trying to put together some basic pages on my localhost that will use HTML and PHP to connect to MySQL to enter things into a database with an HTML form page. 我正在尝试在本地主机上放一些基本页面,这些页面将使用HTML和PHP连接到MySQL,以使用HTML表单页面将内容输入数据库。 The HTML works fine, obviously, but the PHP doesn't seem to want to play with MySQL.
很明显,HTML可以正常工作,但是PHP似乎不想与MySQL一起玩。 I keep getting error messages saying things like this:
我不断收到错误消息,内容如下:
Fatal error: Call to undefined function mysql_connect() in C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\MtG_DB_files\\browse.php on line 24.
The relevant lines on the script I'm writing are as follows: 我正在编写的脚本的相关行如下:
$host="localhost";
$user="XXXXX";
$password="YYYYY";
$dbname="mtg";
/*$cxn=mysql_connect($host,$user,$password,$dbname)or die("Not connecting!");*/
$cxn=mysql_connect("localhost","XXXXX","YYYYY","mtg")or die("Failed to connect to MySQL");
mysql_select_db($cxn,"cardscatalog")or die("Failed to connect to Cards Catalog");
Half of me thinks my problem is syntax and the other thinks the problem is some kind of installation error. 我一半的人认为我的问题是语法,另一半的人认为该问题是某种安装错误。 This all worked fine when I was initially learning it in grad school and using the school's servers and their installations of everything, so I have been able to do it in the past, I just have to figure out what I installed wrong on my personal laptop and how.
当我最初在研究生院学习它并使用学校的服务器及其安装的所有东西时,所有这些工作都很好,所以我过去能够做到这一点,我只需要弄清楚我在个人笔记本电脑上安装了什么错误如何。 I know this is a common problem and I've searched around the Internet trying to find a solution.
我知道这是一个常见问题,因此我在互联网上进行搜索以寻求解决方案。
So far I've tried: 到目前为止,我已经尝试过:
What else can I do or try? 我还能做什么或尝试? I've got to be coming at this from the wrong angle.
我必须从错误的角度出发。 Is there some kind of updated or unincluded file(s) I should download?
我应该下载某种更新或不包含的文件吗? Please let me know of any specs I should include or any additional info needed to help figure this out;
请让我知道我应该包括的任何规格或任何其他信息,以帮助解决这一问题; as you can see, I'm quite new to this and really don't know what I'm doing.
如您所见,我对此很陌生,真的不知道我在做什么。 On a related note, please be specific and fairly idiot-proof if you care to respond...I'm not joking when I say I'm a noob and I don't really speak the jargon and such.;-)Thank you for your time!
与此相关的是,如果您想回应的话,请具体且相当白痴...我不是在开玩笑,说我是菜鸟,我也不是真的在说这种话。;-)谢谢你在你的时间!
EDIT--7/15/14 00:13am Adding a link to my php.ini file for clarification. EDIT--7 / 15/14 00:13 am为我的php.ini文件添加一个链接以进行澄清。
EDIT--7/15/14 23:37pm I'm wondering if this part of my phpinfo gives any useful information: EDIT--7 / 15/14 23:37 pm我想知道我的phpinfo的这一部分是否提供了任何有用的信息:
Path C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Program Files (x86)\\Sony\\VAIO Startup Setting Tool;C:\\Users\\XXXXXX\\AppData\\Local\\Smartbar\\Application\\;C:\\Users\\Marisa\\AppData\\Local\\Smartbar\\Application\\;C:\\Program Files\\jEdit;C:\\Program Files (x86)\\QuickTime\\QTSystem\\;C:\\Program Files (x86)\\MySQL\\MySQL Utilities 1.4.3\\;C:\\Program Files (x86)\\MySQL\\MySQL Utilities 1.4.3\\Doctrine extensions for PHP\\
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
EDIT--7/16/14 10:33 Well I tried re-installing PHP and MySQL last night and nothing doing--no perceptible change in the errors I've been getting. EDIT--7 / 16/14 10:33好吧,我昨晚尝试重新安装PHP和MySQL,却无所事事-我得到的错误没有明显的变化。 I think what might be affecting the problem is that a few of my extensions might have been from older versions of PHP and MySQL I tried to install, so I updated php_mysqli.dll, php_mysql.dll, and php_mbstring.dll, and put them in C:\\php\\ext and C:\\Windows (covering my bases by using both locations), but I discovered I don't appear to have a libmysql.dll file anywhere in the places I thought it might be!
我认为可能会影响该问题的原因是,我的一些扩展可能来自尝试安装的旧版本的PHP和MySQL,因此我更新了php_mysqli.dll,php_mysql.dll和php_mbstring.dll,并将其放入C:\\ php \\ ext和C:\\ Windows(通过使用两个位置来覆盖我的库),但是我发现在我认为可能存在的位置中似乎没有libmysql.dll文件! I've done a little Googling around and it looks like people recommend against downloading a separate libmysql.dll file...what might be a good way to solve this?
我已经做了一些谷歌搜索,看来人们建议不要下载单独的libmysql.dll文件...什么是解决此问题的好方法?
It seems like your php is installed under C:\\PHP if you can get phpinfo() working that means php is running and apache is serving .php files properly. 如果您可以使phpinfo()正常工作,则看来您的php已安装在C:\\ PHP下,这意味着php正在运行,而apache可以正确提供.php文件。
Problem is your extensions are not loading edit php.ini
and make sure you have extension_dir="C:\\PHP\\ext"
set also make sure 问题是您的扩展程序没有加载编辑
php.ini
,并确保设置了extension_dir="C:\\PHP\\ext"
并确保
extension=php_mysql.dll
extension=php_mysqli.dll
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.