当前位置:数据库 > MySQL >>

mysql_query返回值

mysql_query返回值
<?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$sql = "SELECT * FROM Person";
mysql_query($sql,$con);

// 一些代码

mysql_close($con);
?>例子 2
通过 mysql_query() 函数创建一个新数据库:

<?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$sql = "CREATE DATABASE my_db";
if (mysql_query($sql,$con))
  {
  echo "Database my_db created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }
?>

The mysql_query() function executes a query on a MySQL database.
mysql_query()函数的作用是:发送一条 MySQL 查询。

This function returns the query handle for SELECT queries, TRUE/FALSE for other

queries, or FALSE on failure.
如果函数执行成功,它将返回True,并通过SELECT查询语句返回查询结果;如果函数执行

失败,将返回False。

Syntax
语法
mysql_query(query,connection)

Parameter参数 Description描述
query Required. Specifies the SQL query to send (should not end with a

semicolon)
必要参数。指定需要发送的SQL查询语句(不可以以分号“;”结束)
connection Optional. Specifies the MySQL connection. If not specified, the last

connection opened by mysql_connect() or mysql_pconnect() is used.
可选参数。指定MySQL连接。如果不指定该参数,那将默认使用通过mysql_connect()函数

或mysql_pconnect()函数最后一次打开的连接

补充:数据库,mysql教程 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,