
正文
php数据库查询类 php 数据库查询
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
PHP 数据库查询 (分数有加)
SELECT * FROM my_date WHERE (start_dateCURTIME() and end_dateCURTIME());
你函数用错了。
NOW()函数以`'YYYY-MM-DD HH:MM:SS'返回当前的日期时间,可以直接存到DATETIME字段中。
CURDATE()以’YYYY-MM-DD’的格式返回今天的日期,可以直接存到DATE字段中。
CURTIME()以’HH:MM:SS’的格式返回当前的时间,可以直接存到TIME字段中。
相关问答
Q1: php怎样查询数据库(mysql)信息
第一题主要连接数据库,
第二打开连接
第三执行查询
第四判断返回结果
题主可以到w3school上查看具体教程
考虑到不清楚题主安装的环境,暂不贴出代码了。
祝好运,望采纳。
Q2: PHP数据库查询
创建数据库
选择开始菜单中→程序→【Management SQL Server 2008】→【SQL Server Management Studio】命令,打开【SQL Server Management Studio】窗口,并使用Windows或 SQL Server身份验证建立连接。
在【对象资源管理器】窗口中展开服务器,然后选择【数据库】节点
右键单击【数据库】节点,从弹出来的快捷菜单中选择【新建数据库】命令。
执行上述操作后,会弹出【新建数据库】对话框。在对话框、左侧有3个选项,分别是【常规】、【选项】和【文件组】。完成这三个选项中的设置会后,就完成了数据库的创建工作,
在【数据库名称】文本框中输入要新建数据库的名称。例如,这里以“新建的数据库”。
在【所有者】文本框中输入新建数据库的所有者,如sa。根据数据库的使用情况,选择启用或者禁用【使用全文索引】复选框。
在【数据库文件】列表中包括两行,一行是数据库文件,而另一行是日记文件。通过单击下面的【添加】、【删除】按钮添加或删除数据库文件。
切换到【选项页】、在这里可以设置数据库的排序规则、恢复模式、兼容级别和其他属性。
切换到【文件组】页,在这里可以添加或删除文件组。
完成以上操作后,单击【确定】按钮关闭【新建数据库】对话框。至此“新建的数据”数据库创建成功。新建的数据库可以再【对象资源管理器】窗口看到。
Q3: php 数据库查询
select * from 表 where (a='普通工人' or a='合同制工人') and (b='教授' or b='副教授')
Q4: PHP中写一个数据库查询的类的方法代码要如何写
?php
if(!defined("INCLUDE_MYSQL_OK")) {
define("INCLUDE_MYSQL_OK","");
class MySQL_class {
var $debug = true;
var $db,
$id,
$result, /* 查询结果指针 */
$rows, /* 查询结果行数 */
$fields, /* 查询结果列数 */
$data, /* 数据结果 */
$arows, /* 发生作用的纪录行数目 */
$iid; /* 上次插入操作后,可能存在的"AUTO_INCREMENT"属性字段的值,如果为"0",则为空 */
var $user, $pass, $host, $charset;
/*
* 请注意用户名和密码是否正确
*/
function Setup ($host, $user, $pass, $charset='utf8') {
$this-host = $host;
$this-user = $user;
$this-pass = $pass;
$this-charset = $charset;
}
function Connect ($db = "") {
global $CFG_MYSQL_INFO;
if (!$this-host) {
$this-host = $CFG_MYSQL_INFO["host"];
}
if (!$this-user) {
$this-user = $CFG_MYSQL_INFO["user"]; /* 在这里作修改 */
}
if (!$this-pass) {
$this-pass = $CFG_MYSQL_INFO["passwd"]; /* 在这里作修改 */
}
if (!$this-charset) {
$this-charset = "utf8"; /* 在这里作修改 */
}
if (empty($db))
$this-db = $CFG_MYSQL_INFO["database"];
else
$this-db = $db;
$this-id = @mysql_connect($this-host, $this-user, $this-pass);
if (!$this-id)
return false;
$this-SelectDB($this-db); /* 定位到指定数据库 */
$this-Query("SET NAMES '".$this-charset."'");
return true;
}
function Close(){
@mysql_close($this-id);
}
function SelectDB ($db) {
if(!@mysql_select_db($db, $this-id))
return false;
else
return true;
}
function Begin () {
$this-result = @mysql_query("START TRANSACTION WITH CONSISTENT SNAPSHOT", $this-id);
if (!$this-result)
return false;
return true;
}
function Commit () {
$this-result = @mysql_query("COMMIT", $this-id);
if (!$this-result)
return false;
return true;
}
function Rollback () {
$this-result = @mysql_query("ROLLBACK", $this-id);
if (!$this-result)
return false;
return true;
}
function Escape ($str) {
$escstr = mysql_escape_string($str);
return $escstr;
}
# 普通查询功能,主要用于返回结果是多条记录的情况
# 请使用 Fetch 方法取得每条记录信息
function Query ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-rows = @mysql_num_rows($this-result);
$this-fields = @mysql_num_fields($this-result);
if (!$this-rows) return false;
return true;
}
function QuerySql ($query) {
$ret = @mysql_query($query, $this-id);
if ($ret === false)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-result = $ret;
$this-rows = @mysql_num_rows($this-result);
$this-fields = @mysql_num_fields($this-result);
return true;
}
# 如果查询结果为单条记录时使用,返回结果存储于数组 data 中
function QueryRow ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-rows = @mysql_num_rows($this-result);
$this-data = @mysql_fetch_array($this-result, MYSQL_ASSOC);
//MySQL_ErrorMsg ("不能从查询结果中取得数据 $query");
if (!$this-result || !$this-rows)
return false;
return true;
}
# 移动到指定记录行,将该行结果储存于数组 data 中
function Fetch ($row) {
if(!@mysql_data_seek($this-result, $row))
//MySQL_ErrorMsg ("不能定位到指定数据行 $row");
return false;
$this-data = @mysql_fetch_array($this-result, MYSQL_ASSOC);
//MySQL_ErrorMsg ("不能提取指定数据行数据 $row");
if (!$this-data)
return false;
return true;
}
/* 以下方法将作用于 arows */
/* 此方法将作用于 iid */
function Insert ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-arows = @mysql_affected_rows($this-id);
$this-iid = @mysql_insert_id($this-id);
return true;
}
function Update ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-arows = @mysql_affected_rows($this-id);
if (!$this-arows || $this-arows == -1)
return false;
return true;
}
function Delete ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-arows = @mysql_affected_rows($this-id);
return true;
}
function Error (){
return mysql_error()."(".mysql_errno().")";
}
function Errno (){
return mysql_errno();
}
}
/*
* MySQL_ErrorMsg
* 输出错误信息
*/
function MySQL_ErrorMsg ($msg) {
# 关闭可能影响字符显示的HTML代码
echo("/ul/dl/ol\n");
echo("/table/script\n");
# 错误信息
$text = "font color=\"#000000\" style=\"font-size: 9pt; line-height: 12pt\"p系统提示:".$msg."br";
$text .= "错误信息:";
$text .= mysql_error()."br";
$text .= "错误代码:".mysql_errno()."brbr";
$text .= "请稍候再试,如果问题仍然存在,请与 a href=\"mailto:wuqiong@igenus.org\"系统管理员/a 联系php数据库查询类!";
$text .= "/font\n";
die($text);
}
}
?
一些细节的地方自己修改吧 主要是php数据库查询类我在别的文件专门定义了全局变量,你看一遍,把应改的地方改一下就好了
Q5: php数据库查询
mysql_connect("server","user","password");
mysql_select_db('database');
$sql="select count(*) from student where sex='女' union select count(*) from teacher where sex='女'";
$result=mysql_query($sql);
关于php数据库查询类和php 数据库查询的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






