Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
730 views
in Technique[技术] by (71.8m points)

mysql - Command Line PHP mysql_connect() Error

I am running a php page form the command line to update a mysql db once a php exec command has completed. This has been working OK.

However, I have just reinstalled my server and now the script is returning the following error when I run it on the command line:

Fatal error: Call to undefined function mysql_connect() 

The script runs fine in the browser which means mysql is installed OK. How do I enable mysql in PHP to be run from the command line?

Many thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First of all, you can use

php -m

from the command-line, to check which extensions are enabled.

If mysql is not in the list, it means it's not enabled / loaded -- which is probably the case, here.


Then, you'll want to use

php --ini

to check which .ini file(s) is/are read by PHP.


Once you've found out which php.ini file is used, you'll have to edit it, and add something like this :

; configuration for php MySQL module
extension=mysql.so

To load the mysql extension.


Depending on your distribution, the might be a .ini file per extension (Ubuntu does that, for instance).

If that's the case, you could also create a new .ini file (mysql.ini for instance) next to the other ones, and put the two lines I posted into that new file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...