sudo apt-get install php5-cli
示例运行:
<?php $text = "Hello"; $text = mysql_real_escape_string($text); echo $text . "\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
运行~ $ php -m | grep mysql 命令, 可以看到已经安装成功:
mysql
mysqli
pdo_mysql
mysqli.ini mysql.ini opcache.ini pdo.ini pdo_mysql.ini
重新运行命令php demo.php ,出现下面错误:
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
可以看到已经找到函数定义了,出错原因是我当前的机器上启动了lampp, 里面有个mysqld启动了。
运行下面命令 /opt/lampp/bin/php demo.php
可以看到结果出来了:
Hello
php cli mysql_real_escape_string() 函数Fatal error解决办法,布布扣,bubuko.com