Mysql and php link

不言
Release: 2023-03-29 15:14:01
Original
1297 people have browsed it

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"成功";
?>
Copy after login
<?
$conn=@mysql_connect("localhost","root","123456")or dir("链接错误");
?>
Copy after login

Open the database

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

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);
?>
Copy after login

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];
?>
Copy after login

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]可以是数组下标也可以是域名
}
?>
Copy after login

Solution Chinese garbled characters

mysql_query("set names&#39;gbk&#39;);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template