>  기사  >  데이터 베이스  >  php mysql이 데이터베이스 인스턴스_MySQL에 연결됩니다.

php mysql이 데이터베이스 인스턴스_MySQL에 연결됩니다.

WBOY
WBOY원래의
2016-11-30 23:59:381230검색

부담으로 밤에 데이터의 my.ini 인코딩을 utf-8로 변경했는데 데이터베이스가 시작되지 않았습니다. 방금 gbk로 다시 변경했습니다. 문제는.

데이터베이스에 대한 링크이기 때문에 설명할 것이 없으니 그냥 코드대로 들어가시면 됩니다.

<&#63;php

/* Connect to a MySQL server 连接数据库服务器 */
$link = mysqli_connect(
  'localhost', /* The host to connect to 连接MySQL地址 */
  'jian',   /* The user to connect as 连接MySQL用户名 */
  '123456', /* The password to use 连接MySQL密码 */
  'jian');  /* The default database to query 连接数据库名称*/

if (!$link) {
  printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
  exit;
}else
  echo '数据库连接上了!';

/* Close the connection 关闭连接*/
mysqli_close($link);
&#63;>

여기서 jian은 실제로 jian이라는 라이브러리 중 하나의 관리자입니다. 실제 프로젝트에서 얻을 수 있는 것은 라이브러리의 데이터베이스 계정, 비밀번호 및 호스트 주소이기 때문에 데이터베이스 관리자를 작성할 필요가 없습니다. 관리자.

테스트 결과:

원본 데이터베이스 테이블:

작업 1: 점수가 60점 이상인 학생 ID, 수업, 점수 쿼리

jian_scores WHERE 점수에서 id,class,scores 선택>60

모든 코드:

<&#63;php

/* Connect to a MySQL server 连接数据库服务器 */
$link = mysqli_connect(
  'localhost', /* The host to connect to 连接MySQL地址 */
  'jian',   /* The user to connect as 连接MySQL用户名 */
  '123456', /* The password to use 连接MySQL密码 */
  'jian');  /* The default database to query 连接数据库名称*/

if (!$link) {
  printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
  exit;
}else
  echo '数据库连接上了!'. "<br/>";

if ($result = mysqli_query($link, 'SELECT id,class,scores FROM jian_scores WHERE scores>60 ')) {

echo('id 班级 分数 '). "<br/>";

/* Fetch the results of the query 返回查询的结果 */
while( $row = mysqli_fetch_assoc($result) ){
  echo $row['id'], " ", $row['class'], " ", $row['scores'], "<br/>";
  // printf("%s (%s) ", $row['id'],$row['class'], $row['scores']);
}

/* Destroy the result set and free the memory used for it 结束查询释放内存 */
mysqli_free_result($result);
}


/* Close the connection 关闭连接*/
mysqli_close($link);
&#63;>

결과:

읽어주셔서 감사합니다. 도움이 되기를 바랍니다. 이 사이트를 지원해 주셔서 감사합니다!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.