Home >Backend Development >PHP Tutorial >Mysql and php link

Mysql and php link

不言
不言Original
2018-06-02 16:21:231336browse

This article mainly introduces the link between mysql and php, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

mysql establishment link:

Problem Solving

php.ini loads the mysql component

1.extension=php_mysql.dl prefix: remove

2.extension_dir=" "Is the path correct

php link mysql function

mysql_connect: open mysql link

mysql_sqlselect_db: open a database

Link format

mysql_connect("host","host Name", "Password"):

mysql_select_db ("Open database", link identifier): Link identifier, generally defaults to the last opened link

Whether the link is successful

<?
$conn=@mysql_connect("localhost","root","123456")
if($conn)
echo"成功";
?>
<?
$conn=@mysql_connect("localhost","root","123456")or dir("链接错误");
?>

Open the database

<?
$conn=@mysql_connect("localhost","root","123456")or die("链接错误");
mysql_select_db("new",$conn);
?>

Execute sql statement:

Insert

<?
$conn=@mysql_connect("localhost","root","123456") or die("链接错误");
mysql_select_db("new",$conn);
$sql="INSERT INTO test (id,name)"values(‘4’,&#39;zhang&#39;);
mysql_query($sql,$conn);
?>

Query

<?
$conn=@mysql_connect("localhost","root","123456") or die("链接错误");
mysql_select_db("new",$conn);
$sql="SELECT * FORM  ‘test’";
$stt = mysql_query ($sql,$conn);
$row=mysql_fetch_array($stt);
echo $row[name];
?>

Multiple query display

<?
$conn=@mysql_connect("localhost","root","123456") or die("链接错误");
mysql_select_db("new",$conn);
$sql="SELECT * FORM  ‘test’";
$stt = mysql_query ($sql,$conn);
$row=mysql_fetch_array($stt);
while($row=mysql_fetch_array($stt));{
echo$row[name],"<dir>";               [name]可以是数组下标也可以是域名
}
?>

Solution Chinese garbled characters

mysql_query("set names&#39;gbk&#39;);

Related recommendations:

Key points of connection operation between MySQL and php

The above is the detailed content of Mysql and php link. For more information, please follow other related articles on the PHP Chinese website!

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