Get Adobe Flash player
Merry Christmas!

Beginning MySQL and PHP5

MYSQL在PHP5中的应用

1、PHP与mysql建立链接

php.ini 加载mysql组件:
extension=php_mysql.dll 前的; 去掉
extension_dir = " " 路径是否正确

PHP链接mysql函数:
mysql_connect: 开启 MySQL 链接
mysql_select_db: 打开一个数据库
@和or die 隐藏错误 和 条件显示
mysql_connect("主机", "用户名", "密码")
mysql_select_db("打开数据库",连接标识符);
//如果不特别声明连接标识符,则默认为是上一次打开的连接。

2、如何去执行一个SQL语句

mysql_query (SQL语句 ,连接标识符);

说明:mysql_query用来根据连接标识符向该数据库服务器的当前数据库发送查询, 如果连接标识符默认,则默认为是上一次打开的连接。

返回值:成功后返回一个结果标识符,失败时返回false。

$sql = "SELECT * FROM test";
$result = @ mysql_query($sql, $conn) or die(mysql_error

());

3、两种查询函数array / row区别

格式:mysql_fetch_row(result);

说明:mysql_fetch_row用来查询结果的一行保存至数组,该数组下标从0开始,每一个数组元素对应 一个域。通过循环,可以将查询结果全部获得。

格式:mysql_fetch_array(result);

说明:mysql_fetch_array和mysql_fetch_row功能基本相同,只不过它除了可以用从0开始的偏移量作 索引,还可以用域名作索引。值返回下一行的所有域值,并将其保存至一个数组中,没有行时返回false。

mysql_query("set names 'GBK'"); 解决中文乱码

4、 其他常用Mysql函数介绍

mysql_num_rows 用于计算查询结果中所得行的数目
mysql_insert_id 传回最后一次使用 INSERT 指令的 ID。
mysql_tablename 取得数据库名称
mysql_error 返回错误信息
mysql_close 关闭 MySQL 链接

Example:

<?php
$conn = @mysql_connect("yourserver/localhost",

"yourusername", "yourpassword") or die ("Mysql

connection failed, Please check your relative

information!");
mysql_select_db("your database table name", $conn) or

die ("Please check your database, and make sure it is

exists.");

$sql="SELECT * FROM 'yourtablename'";

$selfquery=mysql_query($sql, $conn);
while($row=mysql_fetch_array($selfquery)){
echo $row[name]."<br/><hr>";

mysql_num_rows($selfquery);//统计行数

?>

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

What can i design?

  • Logo Design and Brand Development: Whether you need to create a new brand or revitalize an existing one, I can help. I can design Logo Design, Identity Development, Brand Style Guides, Custom Illustration, Artwork Vectorization and much more!

  • Print Design, Business Collateral Production: I can design Business Systems, Photography, Production Work, business cards, letterhead, brochures, catalogs, mailers and much more!

  • Websites Design and Maintenance: I design killer websites for companies of almost every size and shape. I can design WebSite and WebSite Maintenance, E-Commerce, Content Managment and much more!

  • Creative Marketing and Logo Promotion: I can do Search Engines optimization, Email Marketing, Printed T-shirts, Logo Apparel, Promotion Gifts and much more!

I am a designer who is easygoing, useful, well-organized, independent, skillful, confidence, and calm under pressure.