当前位置: 编程技术>php
本页文章导读:
▪PHP面向对象之将数据库的查询结果序列化成json格式 - 庭上杨柳 <?phpclass link_mysql{private $host,$uid,$pwd,$db,$link,$res;function link_mysql($_host,$_uid,$_pwd,$_db){$this->host = $_host;$this->uid = $_uid;$this->pwd = $_pwd;$this->db = $_db;$this->link = mysql_connect($this->host,$this->.........
▪PHP rtrim函数bug - magic2046 测试代码:<?php$str = rtrim('article_list.html', '.html');echo $str;echo '<br />';$str = rtrim('article_index.html', '.html');echo $str;echo '<br />';$str = rtrim('articleABCT.html', '.html');echo $str;echo '<br />';?> .........
▪while循环中不支持循环使用curl - klj123wan <?php $link = mysql_connect('localhost', 'sms', 'sms');mysql_select_db('sms', $link);mysql_query("set names utf8");$sql = "SELECT phone,chang, msg, linkid, mo_time FROM tables '";$result = mysql_query($sql,$link);$array = array();while($row = mysql_.........
[1]PHP面向对象之将数据库的查询结果序列化成json格式 - 庭上杨柳
<?php
class link_mysql{
private $host,$uid,$pwd,$db,$link,$res;
function link_mysql($_host,$_uid,$_pwd,$_db){
$this->host = $_host;
$this->uid = $_uid;
$this->pwd = $_pwd;
$this->db = $_db;
$this->link = mysql_connect($this->host,$this->uid,$this->pwd);
mysql_select_db($this->db,$this->link);
}
function exec_sql($sql){
//if you use insert sentence,then you must open your link;
$res = mysql_query($sql);
return $res;
}
}
$obj_link = new link_mysql('localhost','***','***','website');
$res = $obj_link->exec_sql("select * from userinfo");
$str = "[";
while($rows = mysql_fetch_assoc($res)){
$str = $str."{name:$rows[name],password:$rows[password],age:$rows[age]},";
}
$str = rtrim($str,',') ."]";
echo $str;
?>
class link_mysql{
private $host,$uid,$pwd,$db,$link,$res;
function link_mysql($_host,$_uid,$_pwd,$_db){
$this->host = $_host;
$this->uid = $_uid;
$this->pwd = $_pwd;
$this->db = $_db;
$this->link = mysql_connect($this->host,$this->uid,$this->pwd);
mysql_select_db($this->db,$this->link);
}
function exec_sql($sql){
//if you use insert sentence,then you must open your link;
$res = mysql_query($sql);
return $res;
}
}
$obj_link = new link_mysql('localhost','***','***','website');
$res = $obj_link->exec_sql("select * from userinfo");
$str = "[";
while($rows = mysql_fetch_assoc($res)){
$str = $str."{name:$rows[name],password:$rows[password],age:$rows[age]},";
}
$str = rtrim($str,',') ."]";
echo $str;
?>
本文链接:http://www.cnblogs.com/xtyang/p/3207422.html,转载请注明。
[2]PHP rtrim函数bug - magic2046
测试代码:
<?php
$str = rtrim('article_list.html', '.html');
echo $str;
echo '<br />';
$str = rtrim('article_index.html', '.html');
echo $str;
echo '<br />';
$str = rtrim('articleABCT.html', '.html');
echo $str;
echo '<br />';
?>
$str = rtrim('article_list.html', '.html');
echo $str;
echo '<br />';
$str = rtrim('article_index.html', '.html');
echo $str;
echo '<br />';
$str = rtrim('articleABCT.html', '.html');
echo $str;
echo '<br />';
?>
显示结果:
article_lis
article_index
articleABCT
测试环境:
WINNT Apache/2.2.16 (Win32) PHP/5.2.14(本地PHPnow 1.5.6-1)
Linux Apache 2.0 PHP/5.2.17p1(wdcp_v2.5.7)
Linux LiteSpeed PHP/5.2.17(梦游主机)
Linux Apache 2.0 PHP/5.2.17(主机无忧)
PHP rtrim函数bug
本文链接:http://www.cnblogs.com/codebox/p/3222501.html,转载请注明。
[3]while循环中不支持循环使用curl - klj123wan
<?php
$link = mysql_connect('localhost', 'sms', 'sms');
mysql_select_db('sms', $link);
mysql_query("set names utf8");
$sql = "
SELECT phone,chang, msg, linkid, mo_time FROM tables '";
$result = mysql_query($sql,$link);
$array = array();
while($row = mysql_fetch_array($result)){
$linkid = $row['phone'].date("YmdHis", strtotime($row['mo_time']));
$str = "SPNUM=".$row['chang']."&MOBILE=".$row['phone']."&CONTENT=".urlencode($row['msg'])."&MOTIME=".urlencode($row['mo_time'])."&LINKID=".$linkid;
$url = "www.baidu.com?".$str;
$array[] = $url;
//var_dump($url); 这里使用curl访问,只能访问一条随后就中断了,只能在上面存放到数组中
/*$result = file_get_contents($url);
var_dump($result);*/
/*$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
// 4. 释放curl句柄
curl_close($ch);*/
}
//var_dump($array);
//这里使用foreach循环执行curl命令
foreach ($array as $url) {
var_dump($url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
// 4. 释放curl句柄
curl_close($ch);
var_dump($result);
}
$link = mysql_connect('localhost', 'sms', 'sms');
mysql_select_db('sms', $link);
mysql_query("set names utf8");
$sql = "
SELECT phone,chang, msg, linkid, mo_time FROM tables '";
$result = mysql_query($sql,$link);
$array = array();
while($row = mysql_fetch_array($result)){
$linkid = $row['phone'].date("YmdHis", strtotime($row['mo_time']));
$str = "SPNUM=".$row['chang']."&MOBILE=".$row['phone']."&CONTENT=".urlencode($row['msg'])."&MOTIME=".urlencode($row['mo_time'])."&LINKID=".$linkid;
$url = "www.baidu.com?".$str;
$array[] = $url;
//var_dump($url); 这里使用curl访问,只能访问一条随后就中断了,只能在上面存放到数组中
/*$result = file_get_contents($url);
var_dump($result);*/
/*$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
// 4. 释放curl句柄
curl_close($ch);*/
}
//var_dump($array);
//这里使用foreach循环执行curl命令
foreach ($array as $url) {
var_dump($url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
// 4. 释放curl句柄
curl_close($ch);
var_dump($result);
}
本文链接:http://www.cnblogs.com/klj123wan/p/3223422.html,转载请注明。
最新技术文章: