php新手 帮忙看一下为何while里面的不执行 谢谢了

WBOY
Release: 2016-06-23 13:50:01
Original
1161 people have browsed it

下面是我的代码:
$conn=mysql_connect("localhost","root","");
if(!$conn)
die("Could not connect:".mysql_error());
if(!mysql_select_db("user2",$conn))
echo "连接数据库失败";
mysql_query("set names utf8",$conn);
mysql_query("create table table1(
id int primary key not null AUTO_INCREMENT,
name varchar(16) not null,
email varchar(16) not null,
age int(16))",$conn);
mysql_query("insert into table1(name,email,age)
values('sun',12345@emial.com,19)",$conn);
echo "hello world!
";
$result=mysql_query("select * from table1",$conn);
while($row=mysql_fetch_row($result))
{
/* echo var_dump($row)."
";
echo "

".var_dump($row)."
";*/
//echo "
 $row[0]--$row[1]--$row[2]";
foreach($row as $value)
{
 echo "--$value";
}
 echo "
";
}
echo "hello";
mysql_free_result($result);
mysql_close();
?>

结果:


回复讨论(解决方案)

检查一下table1中是否有数据

上面代码中不是添加了么 我通过客户端查询不了  
我的客户端查询的结果只有一个数据库information_schema  但是data文件夹下却有通过php创立的数据库 

命令行下查看一下表是否存在,并且查看表中是否有数据。

insert into table1(name,email,age)
values('sun', 12345@emial.com,19)
不需要用引号码?

mysql_query("insert into table1(name,email,age)
values('sun',12345@emial.com,19)",$conn);

这里没有插入成功。

mysql_query("insert into table1(name,email,age)
values('sun',12345@emial.com,19)",$conn);

这里没有插入成功。

mysql_query("insert into table1(name,email,age)
values('sun',12345@emial.com,19)",$conn) or die(mysql_error());

命令行下查看一下表是否存在,并且查看表中是否有数据。








这两个显示为啥不一样(也不知道你能不能看到这个回复)

没创建数据库一样,用Navicate Mysql软件看下。

没创建数据库一样,用Navicate Mysql软件看下。




那个问题解决了 我想问一下9楼的问题能解决么?

你是用什么用户登录的?

你是用什么用户登录的?





这个么 没有登陆啊  就是在mysql中bin文件夹下面有个mysql.exe 然后show databases 出来的

你是以当前windows用户登录mysql的,所以只能看到你能看到的数据库。
运行:mysql.exe with --user=root --password=...  就能看到所有数据库。





太谢谢你了!

你是以当前windows用户登录mysql的,所以只能看到你能看到的数据库。
运行:mysql.exe with --user=root --password=...  就能看到所有数据库。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!