Home  >  Article  >  Backend Development  >  mysql - PHP cli mode to connect to the database

mysql - PHP cli mode to connect to the database

WBOY
WBOYOriginal
2016-08-18 09:15:291790browse

cli mode runs php, including the following code:

<code>echo "开始";
$connection=mysql_connect("localhost","root","123456");
mysql_select_db("mydb");
mysql_query("set names utf8");
echo "数据库连完了";</code>

Then run the script with cli under putty
mysql - PHP cli mode to connect to the database

Only the first line of code is printed, and printing after connecting to mysql is not executed.
Excuse me, why is this?

Resolved: The mysql module was not loaded successfully in multiple environments

Reply content:

cli mode runs php, including the following code:

<code>echo "开始";
$connection=mysql_connect("localhost","root","123456");
mysql_select_db("mydb");
mysql_query("set names utf8");
echo "数据库连完了";</code>

Then run the script with cli under putty
mysql - PHP cli mode to connect to the database

Only the first line of code is printed, and printing after connecting to mysql is not executed.
Excuse me, why is this?

Resolved: The mysql module was not loaded successfully in multiple environments

Post the phpinfo output to see? Is your Linux a Debian system?

Please use pdo

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn