摘要:本文主要向大家介绍了MySQL数据库之PHP7.27: connect mysql 5.7 using new mysqli_connect ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助。
本文主要向大家介绍了MySQL数据库之PHP7.27: connect mysql 5.7 using new mysqli_connect ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助。
<?php
// php 7.27 mysql 5.7 geovindu 涂聚文
$mysql_conf = array(
‘host‘ => ‘127.0.0.1:3306‘,
‘db‘ => ‘sakila‘,
‘db_user‘ => ‘root‘,
‘db_pwd‘ => ‘888888‘,
);
$link = mysqli_connect($mysql_conf[‘host‘],$mysql_conf[‘db_user‘], $mysql_conf[‘db_pwd‘],$mysql_conf[‘db‘]);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "select * from city ORDER BY city_id LIMIT 5;";
// 获取表格字段属性
if ($result = mysqli_query($link, $query)) {
/* Get field information for all fields */
while ($finfo = mysqli_fetch_field($result)) {
printf("Name: %s\n", $finfo->name);
printf("Table: %s\n", $finfo->table);
printf("max. Len: %d\n", $finfo->max_length);
printf("Flags: %d\n", $finfo->flags);
printf("Type: %d\n\n", $finfo->type);
echo("
");
}
mysqli_free_result($result);
}
//
echo("
");
// 显示字段名
if ($result = mysqli_query($link, $query))
{
while($field=mysqli_fetch_field($result))
{
echo("");
}
mysqli_free_result($result);
}
echo("");
// 显示行数据
if ($resultrow = mysqli_query($link, $query))
{
while($row=mysqli_fetch_row($resultrow))
{
echo("");
for($i=0;$i<mysqli_field_count($link);$i++)
{
echo("");
}
echo("");
}
}
echo("
".$field->name." |
".$row[$i]." |
");
/* close connection */
mysqli_close($link);
?>
<?php
// php 7.27 mysql 5.7
/*
character_set_client utf8
character_set_connection utf8
character_set_database utf8 -- 安装mysql时要设置的,所要考虑的
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
*/
session_start();
$mysql_conf = array(
‘host‘ => ‘127.0.0.1:3306‘,
‘db‘ => ‘sakila‘,
‘db_user‘ => ‘root‘,
‘db_pwd‘ => ‘770214‘,
);
// 连接无效
////php.net/manual/zh/function.mysql-connect.php 本扩展自 PHP 5.5.0 起已废弃,并在自 PHP 7.0.0 开始被移除
/*
$mysqli = mysqli_connect($mysql_conf[‘host‘],$mysql_conf[‘db_user‘], $mysql_conf[‘db_pwd‘],$mysql_conf[‘db‘]);
if(!$mysqli)
{
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;//诊断连接错误
}
$mysqli->set_charset(‘utf8‘);
mysqli_query($mysqli,‘set names utf8‘);
*/
//Verbindungen zu mySQL aufbauen
$mysqli = new mysqli($mysql_conf[‘host‘],$mysql_conf[‘db_user‘], $mysql_conf[‘db_pwd‘],$mysql_conf[‘db‘]);
//Verbindung überprüfen
if ($mysqli -> connect_errno)
{
printf("无法建立连接数据库: %s\n", $mysqli->connect_error);
exit();
}
//1.
/*
if (!$select_db) {
die("could not connect to the db:\n" . $mysqli->error);
}
*/
//$mysqli->set_charset(‘utf8‘);
//mysqli_query($mysqli,‘set names utf8‘);
$mysqli->query("set names ‘utf8‘;");//编码转化
$sql = "select * from city where city_id = 601;";
// $res = $mysqli->query($sql);
//mysqli_query($con,"SELECT * FROM Persons");
//$result = $mysqli -> prepare($sql);
//$result -> execute();
$fcoun=mysqli_field_count($mysqli);
printf("geovindu");
echo("字段数:".$fcoun);
// 显示字段名称 where city_id = 601
echo("");
$sql = "select * from city where city_id = 601;";
//$res = $mysqli->query($sql);
/*
if ($res=mysqli_query($mysqli,$sql))
{
// 获取所有列的字段信息
while ($fieldinfo = mysqli_fetch_field($res)) {
printf("字段名: %s\n", $fieldinfo->name);
echo "
";
printf("数据表: %s\n", $fieldinfo->table);
echo "
";
printf("最大长度: %d\n", $fieldinfo->max_length);
echo "
";
}
// 释放结果集
mysqli_free_result($res);
}
*/
/**/
if ($resultd = mysqli_query($mysqli, $sql))
{
// Get field information for all fields
while ($finfo = mysqli_fetch_field($resultd))
{
printf("Name: %s\n", $finfo->name);
printf("Table: %s\n", $finfo->table);
printf("max. Len: %d\n", $finfo->max_length);
printf("Flags: %d\n", $finfo->flags);
printf("Type: %d\n\n", $finfo->type);
echo("
");
}
mysqli_free_result($resultd);
}
// 显示字段名
if ($resfield = mysqli_query($mysqli, $sql))
{
while($field=mysqli_fetch_field($resfield))
{
echo("");
}
mysqli_free_result($resfield);
echo("");
}
//显示某行 where city_id = 601;
$sql = "select * from city";
$res =$mysqli->query($sql);// mysql_query($sql);
while($rowd=$res->fetch_row())
{
echo("");
for($i=0;$i<$res->field_count;$i++)
{
//echo("");
echo("");
}
echo("");
}
echo("
".$field->name." | |
".$res->fields[‘city‘]." | ".$rowd[$i]." |
");
//echo("hi,geovindu");
//
$sql = "select * from city";
$res = $mysqli->query($sql);//mysql_query($sql); //
while ($rowfield = mysqli_fetch_array($res,MYSQLI_ASSOC)) //MYSQLI_BOTH MYSQLI_NUM
{
echo($rowfield[‘city‘] . ‘ ‘ . $rowfield[‘country_id‘]."
");
}
$res->free();
$mysqli->close();
mysqli_close($mysqli);
?>
本文由职坐标整理并发布,希望对同学们学习MySQL有所帮助,更多内容请关注职坐标数据库MySQL数据库频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号