首页 > 编程技术 > php

在oracle中限制返回结果集的大小,类似于mysql的limit(转译)-数据库相关-PHP教程-

发布时间:2016-11-25 17:16

Oracle不支持类似于 MySQL 中的 limit. 但你还是可以rownum来限制返回的结果集的行数.
如果你只希望返回前十行纪录,你可以这样写:
SELECT * FROM table WHERE ROWNUM<10;
但是下面的语句是不对的:
SELECT * FROM table WHERE ROWNUM>90 AND ROWNUM<100;
这是因为 Oracle 认为这个条件不成立,所以没有返回。
你应该这样写:
SELECT * FROM table WHERE ROWNUM<101;
minus
SELECT * FROM table WHERE ROWNUM<91;
 
PHP中操作MySQL数据库的一些要注意的问题
1. 分号的例外    
 对于 MySQL ,第一件你必须牢记的是它的每一行命令都是用分号 (;) 作为结束的,但……没有完全绝对的事,在这儿也是一样,当一行 MySQL 被插入在 PHP 代码中时,最好把后面的分号省略掉,例如:    
mysql_query ("INSERT INTO tablename (first_name, last_name)    
VALUES ('$first_name', '$last_name')    
");    
 这是因为 PHP 也是以分号作为一行的结束的,额外的分号有时会让 PHP 的语法分析器搞不明白,所以还是省略掉的好。在这种情况下,虽然省略了分号,但是 PHP 在执行 MySQL 命令时会自动的帮你加上的。
 
 另外还有一个不要加分号的情况。当你想把要字段的竖者排列显示下来,而不是像通常的那样横着排列时,你可以用 G 来结束一行 SQL 语句,这时就用不上分号了,例如:    
SELECT * FROM PENPALS WHERE USER_ID = 1G    
2. TEXT、DATE、和 SET 数据类型    
 MySQL 数据表的字段必须有定义一个数据类型。这有大约 25 种选择,大部分都是直接明了的,就不多费口舌了。但有几个有必要提一下。
 
 TEXT 不是一种数据类型,虽然可能有些书上是这么说的。它实际上应该是“ LONG VARCHAR ”或者“ MEDIUMTEXT ”。
 
 DATE 数据类型的格式是 YYYY-MM-DD ,比如: 1999-12-08 。你可以很容易的用 date 函数来得到这种格式的当前系统时间:    
date("Y-m-d")    
 并且,在 DATA 数据类型之间可以作减法,得到相差的时间天数:    
$age = ($current_date - $birthdate);    
 集合 SET 是一个有用的数据类型,它和枚举 ENUM 有点相似,只不过是 SET 能够保存多个值而 ENUM 只能保存一个值而已。而且, SET 类型最多只能够有 64 个预定的值,而 ENUM 类型却能够处理最多 65,535 个预定义的值。而如果需要有大于 64 个值的集合,该怎么办呢?这时就需要定义多个集合来一起解决这个问题了。
 
3. 通配符    
第一步、做好数据库的准备。安装数据源(这个就费了我好几天了),首先点击控制面板中的
odbc数据源(32位)
,点击进入后选择
用户DSN(其实是默认的)
,在其中选择
MS ACCESS 97 DATABASE 这一选项,点击其右面的配置按钮。
会出来一个窗口名字是:[Odbc microsoft 安装]。
在其中间部分选择你所要调用的数据库。(选择选取按钮)
再在点击其右侧的高级选项,会弹出一个[高级设置选项]在其中设置用户密码和用户名(每个名称记好了),在栏目下方的选项类型中点击
defaultdir,在最下方的数值中输入你的数据库(也就是access 数据库)。然后一个个确定回到初始位置(用户DSN),这时候开始[添加]你刚才所加的数据源,选择*.mdb(就是access),点击完成。进入到另一个页,在开头数据源中:数据你的数据库源名:(比如我以前使用的是taici.mdb,那么现在在其中输入taici就可以了)。然后肯定要选择你要所找的数据库了。好了,现在数据库可以告一段落了。
第二步,那就是程序倒换的问题了。
<?
$cnx = odbc_connect('taici', 'Admin', 'WSD');
记得吗?教你输入用户跟密码时候叫你记好的,就是Admin 和WSD,知道怎么做了?!
$cur= odbc_exec( $cnx, 'select *    from word' );
其中的word就是其中的一个表taici
$num_row=0;
$conn=mysql_pconnect("localhost","wsd","wsd");// 连接mysql
@mysql_select_db('sms',$conn) or
die("无法连接到数据库,请与管理员联系!");//打开mysql的mydb数据库
while( odbc_fetch_row( $cur ))       //从sql server的mydb库中的user表逐条取出数据,如果对数据进行选择,可在前面的select语句中加上条件判断
{
    $num_row++;
    $field1 = odbc_result( $cur, 1 );     // 这里的参数i(1,2,3..)指的是记录集中的第i个域,你可以有所选择地进行选取,fieldi得到对应域的值,然后你可以对fieldi进行操作
    $field2 = odbc_result( $cur, 2 );     
    $field3 = odbc_result( $cur, 3 );     
    $field4 = odbc_result( $cur, 4 );     
WinMySQLadmin 1.1 以明文形式存放 Mysql 密码漏洞
文章来源:    
涉及程序:
WinMySQLadmin    
    
详细:
WinMySQLadmin 是一个 Mysql 管理软件,发现它以明文形式存放 Mysql 密码于 c:winntmy.ini 文件中。
---<my.ini>---
#This File was made using the WinMySQLadmin 1.1 Tool
[mysqld]
basedir=C:/mysql
datadir=C:/mysql/data
[WinMySQLadmin]
Server=C:/mysql/bin/mysqld-nt.exe
user=admin
password=XXXXX (in clear text)
QueryInterval=30
---<my.ini>---
利用此漏洞,如果远程攻击者能遍历受影响系统,将可能取得数据库管理员权限。如:
http://packetstormsecurity.org/9905-exploits/ms.iis4.showcode.txt


Tutorial for migrating data from MS Access to MySQL
One of the main reasons I started FreeSQL.org is to open up newbie users to the wide world of enterprise-level database access. One of the most common questions I'm asked is "how do I upload my data from my Access database to my MySQL database?" This is far easier than you think and is done using an often overlooked feature of Microsoft Access. Namely, the ability to import, export, and link to non-Access data sources. For now lets just consider MySQL.
The first step is to provide the capability for your windows system to communicate with the remote MySQL server. This is done using MyODBC. If you don't have it installed already, get it from here.
Recently I had to move a database of zipcodes to my MySQL server. I will list the steps I took to migrate this data.
In the windows 98 control panel (or equivalent in WinME, Windows 2000, or XP) open the ODBC Data Source Administrator. You will want to create a new System data source.
Choose "Add", then select the MySQL driver. You should see the following form. Give it a meaningful DSN name, in my case I called it remoteZipCodes. The DSN is how you will identify this connection when you want to use it from another application. Fill in the rest of the necessary information correctly. One tip, MySQL is case sensistive. Make sure you get the username, password, and database case correct.

Here is my source data. A single Access table containing zipcodes by city and state, along with their latitude and longitude.
We want to "export" our data to the remote MySQL server. Select the table you want to export and choose "file/save as/export…" from the main Access menu, then choose "to an external file or database".
The "save table" dialog box will then open and by default will try to export your table to another Access MDB. You change the format of the destination by choosing from the "save as type" combo box. In our case we want to select "ODBC Databases ()". It is probably at the very bottom of the list.
标签:[!--infotagslink--]

您可能感兴趣的文章: