最近开发一个项目,用到这个,记一下:
关键就是两点
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
1
define
(
'
CLIENT_MULTI_RESULTS
'
,
131072
);
2
3 $link = mysql_connect ( " 127.0.0.1 " , " root " , "" , 1 , CLIENT_MULTI_RESULTS) or die ( " Could not connect: " . mysql_error ());
2
3 $link = mysql_connect ( " 127.0.0.1 " , " root " , "" , 1 , CLIENT_MULTI_RESULTS) or die ( " Could not connect: " . mysql_error ());
下面就可以正常使用了,以下是例子程序。
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
1
<?
php
2 define ( ' CLIENT_MULTI_RESULTS ' , 131072 );
3
4 $link = mysql_connect ( " 127.0.0.1 " , " root " , "" , 1 , CLIENT_MULTI_RESULTS) or die ( " Could not connect: " . mysql_error ());
5 mysql_select_db ( " vs " ) or die ( " Could not select database " );
6 ?>
7
8 <? php
9 $result = mysql_query ( " call get_news_from_class_id(2) " ) or die ( " Query failed: " . mysql_error ());
10 while ( $row = mysql_fetch_array ( $result , MYSQL_ASSOC))
11 {
12 $line = ' <tr><td><a target = _blank href=\ '' .$row["url"]. ' \ ' > ' . $row [ " title " ] . ' ( ' . $row [ " page_time " ] . ' ) ' . ' </a></td></t r> ' ;
14 echo $line ;
15 printf ( " \n " );
16
17 }
18 mysql_free_result ( $result );
19 ?>
20
21 <? php
22 mysql_close ( $link );
23 ?>
2 define ( ' CLIENT_MULTI_RESULTS ' , 131072 );
3
4 $link = mysql_connect ( " 127.0.0.1 " , " root " , "" , 1 , CLIENT_MULTI_RESULTS) or die ( " Could not connect: " . mysql_error ());
5 mysql_select_db ( " vs " ) or die ( " Could not select database " );
6 ?>
7
8 <? php
9 $result = mysql_query ( " call get_news_from_class_id(2) " ) or die ( " Query failed: " . mysql_error ());
10 while ( $row = mysql_fetch_array ( $result , MYSQL_ASSOC))
11 {
12 $line = ' <tr><td><a target = _blank href=\ '' .$row["url"]. ' \ ' > ' . $row [ " title " ] . ' ( ' . $row [ " page_time " ] . ' ) ' . ' </a></td></t r> ' ;
14 echo $line ;
15 printf ( " \n " );
16
17 }
18 mysql_free_result ( $result );
19 ?>
20
21 <? php
22 mysql_close ( $link );
23 ?>
另外说个事,因为最近用的是FleaPHP这个框架进行开发的.设置了DSN的options发现没有作用,debug了一下发现问题出在FLEA::parseDSN函数中,代码如下:
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
1
function
parseDSN(
$dsn
)
2 {
3 if ( is_array ( $dsn )) {
4 $dsn [ ' host ' ] = isset ( $dsn [ ' host ' ]) ? $dsn [ ' host ' ] : '' ;
5 $dsn [ ' port ' ] = isset ( $dsn [ ' port ' ]) ? $dsn [ ' port ' ] : '' ;
6 $dsn [ ' login ' ] = isset ( $dsn [ ' login ' ]) ? $dsn [ ' login ' ] : '' ;
7 $dsn [ ' password ' ] = isset ( $dsn [ ' password ' ]) ? $dsn [ ' password ' ] : '' ;
8 $dsn [ ' database ' ] = isset ( $dsn [ ' database ' ]) ? $dsn [ ' database ' ] : '' ;
9 $dsn [ ' options ' ] = isset ( $dsn [ ' options ' ]) ? serialize ( $dsn [ ' options ' ]) : '' ;
2 {
3 if ( is_array ( $dsn )) {
4 $dsn [ ' host ' ] = isset ( $dsn [ ' host ' ]) ? $dsn [ ' host ' ] : '' ;
5 $dsn [ ' port ' ] = isset ( $dsn [ ' port ' ]) ? $dsn [ ' port ' ] : '' ;
6 $dsn [ ' login ' ] = isset ( $dsn [ ' login ' ]) ? $dsn [ ' login ' ] : '' ;
7 $dsn [ ' password ' ] = isset ( $dsn [ ' password ' ]) ? $dsn [ ' password ' ] : '' ;
8 $dsn [ ' database ' ] = isset ( $dsn [ ' database ' ]) ? $dsn [ ' database ' ] : '' ;
9 $dsn [ ' options ' ] = isset ( $dsn [ ' options ' ]) ? serialize ( $dsn [ ' options ' ]) : '' ;
这里多加了个serialize,不知道是开发人员手误还是咋的.