Fatal error: Call to undefined function mysql_connect() cannot solve - php

I have searched this error in Google and tried everything I found, but it still does not work.
I have set in my php.ini
extension_dir ="C:\php\ext\"
uncommented
extension=php_mysql.dll
extension=php_mysqli.dll
these files are present in the extension path, and I restarted Apache.
But phpinfo(); still does not show anything about MySQL. So do you have any suggestions to load these modules?
note: I am using Windows 7 (64 bit), MySQL 5.5, Apache 2.0.49 and PHP 5.3.16

Finally, I solved the same problem, so, here is my solution. I guess the last slash in the line
extension_dir ="C:\php\ext\
could make troubles. Just let it as
extension_dir ="C:\php\ext
Moreover, try to approach the problem the following way:
*My PC is running Windows 7 (Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a), the syntax in the file "httpd.conf" (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf) was sensitive to slashes.
You can check if "php.ini" is read from the right directory. Just type in your browser "localhost/index.php". The code of index.php is the following:
<?php
echo phpinfo();
?>
There is the row (not far from the top) called "Loaded Configuration File". So, if there is nothing added, then the problem could be that your "php.ini" is not read, even you uncommented (extension=php_mysql.dll and extension=php_mysqli.dll). So, in order to make it work I did the following step. I needed to change from
PHPIniDir 'c:\PHP\'
to
PHPIniDir 'c:\PHP'
Pay the attention that the last slash disturbed everything!
Now the row "Loaded Configuration File" gets "C:\PHP\php.ini" after refreshing "localhost/index.php" (before I restarted Apache2.2) as well as mysql block is there. MySQL and PHP are working together!*

I have been having the exact same problem as you. And I (literally) solved it 2 minutes ago.
I am running Apache 2.4 64 bit on Win 7.
The version of php I downloaded gave me two php.ini files:
1)php.ini-production and
2)php.ini-development
I thought that was all gravy and every time I made a change to one, I did the exact same thing to the other.
When I first encountered the problem I loaded index.php (on my local server) and looked at the sixth box from the top called "Loaded configuration file". It simple said "nothing."
I then referenced this page and found how PHP (once started) goes about looking for the php.ini file. I tried putting both the development and production (referenced above) files in all the directories that the above link specified. Nothing.
Then I thought, what the hell it's worth a shot, and changed the php.ini-production to just "php.ini".
Bam. It started working. Such a simplistic fix but I suppose it makes sense as to why Apache wasn't able to find "php.ini." The file didn't exist verbatim.
I really hope this helps, running into this problem sure sucked.
And I'm sorry if any of this seems patronizing because it is so simple. I always troubleshoot from this site and so many of the answers require more than a fundamental understanding of a subject, and since this seems like a problem(and a solution) that beginners will struggle with, I thought I would spell it out in a way that I would have appreciated 6 months ago.

Related

PHP: how to access phpMyAdmin / weird conflict between php.ini and extension_dir

First, this is my first post & I have spent the last five hours trying to read all I can to solve this.
I am new to PHP/mySQL, on Windows, using MAMP, PHP version 7.4.1 and trying to access phpMyAdmin, which gave me the famous error "the mysqli extension is missing", that is why I started researching on this.
After trying every solution I found on the internet (uncommenting lines in php.ini, running a script to see if extensions were loading, downgrading to PHP version 7.3.7, uninstalling & reinstalling MAMP, etc) and running many tests I finally understood part of the problem I was having :
• every time I set php.ini to display errors (deleting the ";" before the two lines & setting display_errors on "On"), it mysteriously changes the extension_dir I can see in the php.info page to another directory. I can't change it back using php.ini (it doesn't work), thus the extension mysqli.dll won't load (I can check it doesn't with a script). I have tried putting it in a new directory I created to match the path it said, but it doesn't work either.
• when I revert the php.ini file to not displaying errors (that is, when I add the two ; back where they were before), the extension_dir changes back to the right repertory and it works! The extensions load and I can access phpMyAdmin.
It doesn't make any sense at all to me. Maybe deleting just one ";" in the php.ini causes the extension_dir to change to something else, but I don't get why, especially when every php tutorial I've read tells me that it's the way to displaying errors.
I would like to keep seeing my code errors AND access phpMyAdmin via MAMP, and at this point my brain feels like mashed potatoes, so if you have any idea of what is going on here...
Alright I found what caused the problem and it was text in the php.ini I forgot to remove!

Can't run PHP after a new installation of XAMPP

I have been a happy user of XAMPP for years,
but today I have updated to the latest Windows 32 bit version on a Windows 10 machine.
I couldn't see a 64 bit version.
Anyway, all went well,
and once I changed some settings, I was able to see all my old databases under the new phpMyAdmin.
But my PHP scripts are bombing out before they start.
Even phpinfo gives the same error message, which is...
"Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'F:/My Documents/OneDrive/Webs/htdocs/index.php'
(include_path='.;C:/xampp/php/pear/PEAR') in Unknown on line 0"
The test script of index.php is nothing more than
<?php echo "HELLO"; ?>
The statement in php.ini is
include_path = ".;C:/xampp/php/pear/PEAR"
and there are no other include_path statements.
The directory C:/xampp/php/pear/PEAR does exist.
The index.php file is there.
I don't know why there's a PEAR folder inside a pear folder - that's how Xampp installed it.
I have tried all variations of that include_path statement to no avail.
I have left out one of the pears.
Leaving out the include_path statement altogether just results in the PHP default which is a folder which is definitely not there, so that's no good.
My localhost is inside the OneDrive folder as you can see from the error message, but I have been doing it that way for years.
Now I cannot run any PHP scripts. Pure HTML is no problem.
The new installation of Xampp has totally replaced the old one, and its Control Panel v3.2.2 looks to be working perfectly.
phpMyAdmin seems to be working fine, but not phpinfo, as said.
I have scanned the web for answers to this, and there is plenty of forum Q&A's, but they all tell me to do what I have done.
The computer is Windows 10 Pro, and is fully up to date. Apache 2.4.33.
PHP 5.6.35. Database server is 10.1.31 MariaDB.
I've run out of ideas. Any help will be appreciated.
Thanks Mike.
You need to fix your include_path system variable to point to the correct location.
To fix it edit the php.ini file. In that file you will find a line that says, "include_path = ...". (You can find out what the location of php.ini by running phpinfo() on a page.) Fix the part of the line that says, "\xampplite\php\pear\PEAR" to read "C:\xampplite\php\pear". Make sure to leave the semi-colons before and/or after the line in place.
Restart PHP and you should be good to go. To restart PHP in IIS you can restart the application pool assigned to your site or, better yet, restart IIS all together.
first: check all the paths in the php. ini ( use a search or a grep to check them)
second: check that you don't have any extensions added twice (one in the beginning and one in the end of the file)

php.ini is overwritten locally whenever project is run

Okay, I've been having issues with PDO connection strings in a new VS.PHP 3.3 project.
I have found the main, apparent, cause of this is that in phpinfo() PDO drivers shows "no value".
Having scoured the net I followed all instructions and found the in php.ini
extension=php_pdo_mysql.dll
was remarked out. I unremarked and saved. This made no difference. I then noticed that
Loaded Configuration File linked to "E:\Website\Website\php.ini
which is the local project folder. Unable to see a file here I assumed it was hidden and, sure enough, when I showed the hidden file, there it was. I opened and noticed that, as above, the extension was remarked out. I amended, saved, re-ran phpinfo() and there was no change. In going back into the local php.ini all changes had reverted back.
I have changed the three php.ini files that are saved in "PHP 5.2", "PHP 5.3" and "PHP 5.4" and none of them reflect the local php.ini.
I have no idea where to go next. Really hoping someone can point out my deliberate mistake.
Panic over, problem solved.
For anyone who suffers from the same problem, this is how it is solved....
In the PHP 5.4 directory there is a config file "php-xdebug". This is where you need to change the extensions. This is where VS was overwriting from.

How do I get php curl to run on my apache2.x Development server?

Before I begin, I will add that I've spent much time googling this and have attempted several solutions none of which have worked.
System Info:
Windows 7 Professional (x86, 32 bit )
Apache2 up and running C:\Program Files\Apache Software Foundation\Apache2.2\
PHP 5.3.8 C:\Program Files\PHP Also works.
manually configured httpd.conf to enable php, note that php is working, except for curl.
I have enabled curl in my php.ini C:\Program Files\PHP\php.ini
This is near the end of my php.ini
[PHP]
extension_dir = "ext"
[PHP_CURL]
extension=php_curl.dll
Note also that the file C:\Program Files\PHP\ext\php_curl.dll exists!
I have restarted the apache server and yet curl still does not function.
a quick test.php file:
<?php
$curl_conn = curl_init();
?>
note that I have both php start and end tags correct stackoverflow just isn't showing the start php tag.
puts out:
Fatal error: Call to undefined function curl_init() in E:\path\to_project\test.php on line 3
I have now spent 3 hours trying to get curl to work, google has no helped, most of the solutions seem to involve making sure that the extension=module line in php.ini is not commented out, and as you can see above it is not commented out so that advice doesn't seem to help me.
Any ideas would be appreciated as this is rather frustrating.
Thanks!
You should add "C:\PHP" to the server's PATH environment variable:
Right-click on My Computer, choose Properties
Flip to the Advanced tab
Click the Environment Variables button
Double-click the Path variable in the list of System variables.
Either add "C:\PHP;" to the beginning or ";C:\PHP" to the end (sans quotes, not both).
Restart your computer for it to take effect.
Thanks to:
http://www.webcheatsheet.com/PHP/install_and_configure.php
I know this thread has long been closed, but for anyone like myself who encounters this problem subsequently, for me, the answer turned out to be a DIFFERENT copy of the php.ini file was being loaded than what I thought. I was editing the php.ini file in my PHP 5.4.3 directory, and there is another copy of the php.ini file that resides in the Apache directory - identical as far as I could tell from a quick glance.
De-commenting the extension=php_curl.dll line IN THE RIGHT FILE, the Apache folder, enabled the curl function for me.
Jeff S.
Have you copied cURL dependency files:
libeay32.dll
ssleay32.dll
to C:\Windows\System32 folder?
It could be that PHP cannot find these two files to run cURL extension.

MySQL not working with php; and crashing apache when enabled

I just recently setup a fresh install of PHP, Mysql and Apache on my Windows 2003 server. Php is working fine and my Navicat MySQL browser can connect to my tables. However no matter what I do. MySQL doesn't show in phpInfo() even though I have the extensions in my ext folder. I installed PHP via the windows binary installer. Any idea what I'm missing? I'm pretty new to PHP is this is the first time I've tried to setup my own server I'm sure I'm missing something simple. Thanks.
--- EDIT ---
So as suggested by Alan Geleynse I added the extension to my php.ini, now Apache crashes every time I try to enable php_mysql.dll any ideas on this one? I may just restart my php from scratch if this is any more trouble.
You probably need to enable the extension in your php.ini
Search through php.ini for extension and you should see a list, some of which will be commented out. If you remove the comment for MySQL, it should load the extension.
If you do not see it, you should be able to add this line to your php.ini. Make sure that the dll listed is the one you want and is located in your extension directory.
extension=mysql.dll
Seems the issue was not only a missing php_mysql.dll but I was also missing libmysql.dll The installer still borked the install of the extension files though. Oh well it happens thanks to everyone for the help.
Probably apache crashes because of missing dll. There is probably a directory 'ext' in your php installation dir. Check whether there is a 'php_mysql.dll' file in it.
Also, check for directive 'extension_dir' in your php.ini, it must point to the location of extensions directory. For example, I have php installed in 'C:\php' and 'C:\php\ext' folder in it. My php.ini contains line:
extension_dir = "C:/php/ext"
I just fixed this problem on my computer by copying libMysql.dll from the MySql server directory to c:/windows/system32/, just a few minutes ago.

Categories