当前位置:Gxlcms > 数据库问题 > php mysql

php mysql

时间:2021-07-01 10:21:17 帮助过:32人阅读

参考链接:

https://www.runoob.com/php/php-mysql-create.html

PHP连接Mysql

以下两种方式:
Mysqli extension
PDO

mysqli执行sql语句

$query = "select first_name,last_name" from users where user_id=‘$id‘";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_assoc($result)){
$first = $row["first_name"];
$last = $row["last_name"];
$html .= "

ID: {$id}
First name: {$first}
Surname: {$last}
";
}

PDO执行sql语句

$data = $db->prepare( ‘SELECT first_name, last_name FROM users WHERE user_id = (:id) LIMIT 1;‘ );
$data->bindParam( ‘:id‘, $id, PDO::PARAM_INT );
$data->execute();
$row = $data->fetch();
当然还有对于整数的查询和模糊查询,加上对应的闭合即可。

php mysql

标签:soc   mys   select   last   result   HERE   while   语句   sso   

人气教程排行