使用PHP访问MySQL数据库 [英] Using PHP to access a MySQL database

查看:78
本文介绍了使用PHP访问MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PHP访问MySQL数据库.

I would like to access a MySQL database using PHP.

有人可以解释一下其中涉及的基本步骤吗?

Can someone please explain the basic steps involved in doing that?

推荐答案

我建议您使用mysqli扩展名,而不是旧的,不安全的mysql扩展名.

I would suggest that you use the mysqli extension as opposed to the old, insecure mysql extension.

首先熟悉数据库设计,SQL和MySQL,然后按照此链接

First get familiar with database design, SQL and MySQL, then follow this link.

还是想举个例子吗?在这里,您去了:

Still want an example? Here you go:

<?php
$host = 'YOUR HOSTNAME HERE';
$user = 'YOUR USERNAME HERE';
$pass = 'YOUR PASSWORD HERE';
$db_name = 'YOUR DATABASE NAME HERE';

$db = new mysqli( $host, $user, $password, $db_name );

if( $db->errno ) {
  // an error occurred.
  exit();
}
...
$sql = 'SELECT * FROM some_table;';    

$result_set = $db->query( $sql );

...fetch results...

while( $obj = $result_set->fetch_object() ) {
   $value = $obj->some_property;
   ...do something with $value...
}

$db->close();

?>

Nuff说.

祝你好运!

这篇关于使用PHP访问MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆