PHP一直报错误,,麻烦各位帮我看看,谢谢
PHP一直报错误,,麻烦各位帮我看看,谢谢<?phprequire'dbset.php'$con=mysql_connect($dbserver,$dbuser,$dbp...
PHP一直报错误,,麻烦各位帮我看看,谢谢<?php
require'dbset.php'
$con = mysql_connect($dbserver,$dbuser,$dbpwd);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
就是连接数据库那行,一开始自己写的不行,后来逼急了从w3school上copy下来还不行。。。麻烦各位帮我看看,谢谢 展开
require'dbset.php'
$con = mysql_connect($dbserver,$dbuser,$dbpwd);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
就是连接数据库那行,一开始自己写的不行,后来逼急了从w3school上copy下来还不行。。。麻烦各位帮我看看,谢谢 展开
展开全部
require'dbset.php' 这后面少了 分号
require'dbset.php';
顺便给你几个例子 ,原生,mysqli ,pdo 连接数据库
function actionIndex(){
//echo 'index page!';
$con = mysql_connect('127.0.0.1:3306','root','root');
mysql_select_db('test',$con);
$result = mysql_query("SELECT * FROM user_info");
while($row = mysql_fetch_array($result))
{
echo $row['u_id'] . " " . $row['u_name'];
echo "<br />";
}
mysql_close($con);
}
function actionMysqli(){
$con = mysqli_connect('127.0.0.1','root','root','test','3306');
$res = mysqli_query($con,'select * from user_info ');
$arr = mysqli_fetch_array($res);
print_r($arr['u_id']);
mysqli_close($con);
/* $db = new mysqli('127.0.0.1:3306','root','root','test');
$result = $db->query('select * from user_info ');
while($row = $result->fetch_array())
{
echo $row['u_id'] . " " . $row['u_name'];
echo "<br />";
}
*/
}
function actionMysqlpdo(){
$db = new PDO('mysql:host=127.0.0.1:3306;dbname=test','root','root');
$res = $db->query('select * from user_info ');
$res = $res->fetchAll(PDO::FETCH_ASSOC);
print_r($res);
exit;
foreach ($res as $k=>$row) {
echo $row['u_id'] . " " . $row['u_name'];
echo "<br />";
}
}
追问
谢谢,😁😁😉😊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询