php连接mysql代码,尽量详细.谢谢了!
我刚学PHP两天,写了一段代码:<?php$dbhost='localhost';$dbuser='root';//我的用户名$dbpass='welcome';//我的...
我刚学PHP两天,写了一段代码:
<?php
$dbhost = 'localhost';
$dbuser = 'root'; //我的用户名
$dbpass = 'welcome'; //我的密码
$dbname = 'mydb'; //我的mysql库名
$connect = mysql_connect($dbhost,$dbuser,$dbpass,$dbname);
if ($connect) {
echo "非常好,成功了!)";
} else {
echo "不好意思,失败了!";
}
?>
结果错误如下:
Fatal error: Call to undefined function mysql_connect() in D:\myPHP\mytest\conn.php on line 6
哪位大哥给我一段完整详细的代码或是帮我指点错误也行.
谢谢了! 展开
<?php
$dbhost = 'localhost';
$dbuser = 'root'; //我的用户名
$dbpass = 'welcome'; //我的密码
$dbname = 'mydb'; //我的mysql库名
$connect = mysql_connect($dbhost,$dbuser,$dbpass,$dbname);
if ($connect) {
echo "非常好,成功了!)";
} else {
echo "不好意思,失败了!";
}
?>
结果错误如下:
Fatal error: Call to undefined function mysql_connect() in D:\myPHP\mytest\conn.php on line 6
哪位大哥给我一段完整详细的代码或是帮我指点错误也行.
谢谢了! 展开
3个回答
展开全部
<?php
$mysql_server_name='localhost';
$mysql_username='root';
$mysql_password='12345678';
$mysql_database='mycounter';
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
$sql='CREATE DATABASE mycounter DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
';
mysql_query($sql);
$sql='CREATE TABLE `counter` (`id` INT(255) UNSIGNED NOT NULL AUTO_INCREMENT ,`count` INT(255) UNSIGNED NOT NULL DEFAULT 0,PRIMARY KEY ( `id` ) ) TYPE = innodb;';
mysql_select_db($mysql_database,$conn);
$result=mysql_query($sql);
//echo $sql;
mysql_close($conn);
echo "Hello!数据库mycounter已经成功建立!";
?>
$mysql_server_name='localhost';
$mysql_username='root';
$mysql_password='12345678';
$mysql_database='mycounter';
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
$sql='CREATE DATABASE mycounter DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
';
mysql_query($sql);
$sql='CREATE TABLE `counter` (`id` INT(255) UNSIGNED NOT NULL AUTO_INCREMENT ,`count` INT(255) UNSIGNED NOT NULL DEFAULT 0,PRIMARY KEY ( `id` ) ) TYPE = innodb;';
mysql_select_db($mysql_database,$conn);
$result=mysql_query($sql);
//echo $sql;
mysql_close($conn);
echo "Hello!数据库mycounter已经成功建立!";
?>
展开全部
你这个不是数据库的问题,而是你的php还没有支持mysql,重装php,在prefix写上mysql。这样就不会有line 6的错误提示了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?php
$mysql_server_name='localhost';
$mysql_username='root';
$mysql_password='12345678';
$mysql_database='mycounter';
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
$sql='CREATE
DATABASE
mycounter
DEFAULT
CHARACTER
SET
gbk
COLLATE
gbk_chinese_ci;
';
mysql_query($sql);
$sql='CREATE
TABLE
`counter`
(`id`
INT(255)
UNSIGNED
NOT
NULL
AUTO_INCREMENT
,`count`
INT(255)
UNSIGNED
NOT
NULL
DEFAULT
0,PRIMARY
KEY
(
`id`
)
)
TYPE
=
innodb;';
mysql_select_db($mysql_database,$conn);
$result=mysql_query($sql);
//echo
$sql;
mysql_close($conn);
echo
"Hello!数据库mycounter已经成功建立!";
?>
$mysql_server_name='localhost';
$mysql_username='root';
$mysql_password='12345678';
$mysql_database='mycounter';
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
$sql='CREATE
DATABASE
mycounter
DEFAULT
CHARACTER
SET
gbk
COLLATE
gbk_chinese_ci;
';
mysql_query($sql);
$sql='CREATE
TABLE
`counter`
(`id`
INT(255)
UNSIGNED
NOT
NULL
AUTO_INCREMENT
,`count`
INT(255)
UNSIGNED
NOT
NULL
DEFAULT
0,PRIMARY
KEY
(
`id`
)
)
TYPE
=
innodb;';
mysql_select_db($mysql_database,$conn);
$result=mysql_query($sql);
//echo
$sql;
mysql_close($conn);
echo
"Hello!数据库mycounter已经成功建立!";
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询