PHP初学者学习实例
.$dbhost = 'localhost';
$dbuser = 'root'; //你的mysql用户名
$dbpass = '123456'; //你的mysql密码
$dbname = 'data'; //你的mysql库名
//连接本地数据库
$GLOBALS["conn"] = mysql_connect($dbhost,$dbuser,$dbpass);
//打开数据库
mysql_select_db($dbname,$GLOBALS["conn"]);
?>
2.php读取数据库中,某一字段值
<?php
//读取一列数据
$sql="select * from ec_admin";
$result = mysql_query($sql,$GLOBALS["conn"]);
printf("用户名: %s<br>\n", mysql_result($result,3,"UserName"));
printf("密码: %s<br>\n", mysql_result($result,3,"UserPass"));
?>
相关文档:
本文列出了所有初学者最常见的PHP问题
【1】页面之间无法传递变量 get,post,session在最新的php版本中自动全局变量是关闭的,所以要从上一页面取得提交过来得变量要使用$_GET['foo'],$_POST['foo'],$_SESSION['foo']来得到
当然也可以修改自动全局变量为开(php.ini改为register_globals = On);考虑到兼容性,还是强迫 ......
[PHP]
;;;;;;;;;;;;;;;;;;;
; About php.ini ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.
; PHP attempts to find and load this configuration from a number of locations.
; The follo ......
Php Variable Circular References
Circular-references has been a long outstanding issue with PHP. They are
caused by the fact that PHP uses a reference counted memory allocation
mechanism for its internal variables. This causes problems for longer
running scripts (such as an Applicatio ......
在PHP里,如果你没有手写构造函数,则php在实例化这个对象的时候,会自动为类成员以及类方法进行初始化,分配内存等工作,但是有些时候不能满足我们的要求,比如我们要在对象实例化的时候传递参数,那么就需要手动编写构造函数了,手写构造函数有两种写法,只是表现形式不同,其实本质一样
class test
{
&nb ......
循环引用一直是PHP(应用)中一个突出的问题。问题的出现是由于这样的一个事实:PHP为php内部变量使用一个“引用计数器”内存分配机制。这一机制对一些相比来说较长时间运行的脚本(比如,应用服务器或者eZ测试组件)会引发问题,因为内存在脚本结束前事不会被释放掉的。但是,(几乎)没有人 ......