php7 docking mysql pit avoidance guide

php7 docking mysql pit avoidance guide! When I followed the video tutorial, I found some annoying things. Share it with everyone.

Hope this helps you avoid some unnecessary twists and turns. For example, what I shared today is what happens when php7 connects to mysql.

First of all, declare: php7 docking mysql, you can use mysql5.7 version.

As shown in the picture, my mysql version is 5.7. Here is a screenshot of the successful connection.

 

As shown in the picture, this is a test.php test file written in apache. Called some functions, mysqli modules. This function comes with it.

<?php
	$con = new mysqli('localhost','root','','myseo');

	if(!$con)

	die("connect error:".mysqli_connect_error());

	else

	echo "success connect mysql\n";

	$sql = "select *  from user";

	$rs = $con->query($sql);

	$c = array();

	while($r = $rs->fetch_row()){

	array_push($c,substr($r[0],0,4));

	}

	$c = array_unique($c);

	$i=0;

	$zy = array();

	foreach($c as $row){

	array_push($zy,$row);

	}

	print_r($zy);

	$con->close();

?>

 Statement, my mysql, root is yes, but no password is set, so the password is empty. The following myseo is the name of the database you want to connect to.

I won’t explain it later, you can understand it by yourself.


Description of troublesome things:

When I was learning according to the video tutorial of station b, the php5 used by the teacher, its configuration files and configuration parameters, and the docking components of mysql are different. different. And, most annoyingly. After the teacher calls phpinfo();, the interface will display that the mysql module has been loaded successfully. I mistakenly thought that php7 would also display this content. After 1 hour of tossing. came to a conclusion. php7 will not display that content .

But it doesn't mean that your configuration is wrong. Your program can successfully connect to the mysql database. as the picture shows.

I hope everyone avoids this pit.

Guess you like

Origin blog.csdn.net/yrldjsbk/article/details/131310647