萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> mysql_query返回值

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()函數最後一次打開的連接

copyright © 萬盛學電腦網 all rights reserved