php cli mysql_real_escape_string() 函數(shù)Fatal error解決辦法
sudo apt-get install php5-cli
示例運(yùn)行:
運(yùn)行php demo.php?
PHP Fatal error: ?Call to undefined function mysql_real_escape_string() in /home/youfu/demo.php on line 6
解決辦法
sudo?apt-get?install?php5-mysql
運(yùn)行~ $ php -m | grep mysql 命令, 可以看到已經(jīng)安裝成功:
mysql
mysqli
pdo_mysql
或者運(yùn)行下面命令?~ $ ls /etc/php5/mods-available/
mysqli.ini ?mysql.ini ?opcache.ini ?pdo.ini ?pdo_mysql.ini
重新運(yùn)行命令php demo.php?,出現(xiàn)下面錯(cuò)誤:
PHP Warning: ?mysql_real_escape_string(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/youfu/demo.php on line 6
PHP Warning: ?mysql_real_escape_string(): A link to the server could not be established in /home/youfu/demo.php on line 6
可以看到已經(jīng)找到函數(shù)定義了,出錯(cuò)原因是我當(dāng)前的機(jī)器上啟動(dòng)了lampp, 里面有個(gè)mysqld啟動(dòng)了。
運(yùn)行下面命令 /opt/lampp/bin/php demo.php
可以看到結(jié)果出來(lái)了:
Hello