Mysql connect v. pconnect
| From: | Chuck Glaazart | Date: | Sat, 02 Sep 2000 17:13:46 +0000 |
| Subject: | Mysql connect v. pconnect | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-14934@lists.php.net to get a copy of this message | ||
Take my word that my tables and fieldnames are ok. In this snipped, futzing with classes for db -
the code works as *I* expect it to if I use mysql_connect - that is the loops and conditionals and
echos work. If I use mysql_pconnect the loops and conditionals work, but the echo of the fields
from $myobj2->name all come up null. I tried using mysql_fetch_row and the proper index with the
same result.
I also eched the $link and $result from $myobj and $myobj2 under both connect and pconnect and they
seemed backwards ... under connect, $link registeres '1' for both, whereas under pconnect
it registers '1' and '2' for $myobj and $myobj2 respectively.
It seems to me like they should work the other way around. I took a spin through the manual and
found nothing useful ... can anyone shed any light on this behaviour?
here's the code.
<?php
class mydb {
var $host="192.168.1.69";
var $user="root";
var $pass="";
var $database="solutions";
var $link;
var $qres;
function mydb() {
$this->link=mysql_connect($this->host,$this->user,$this->pass);
$result=mysql_select_db($this->database,$this->link);
return;
}
function query($qstr) {
$this->qres=mysql_query($qstr,$this->link);
return;
}
function nextobj() {
$obj=mysql_fetch_object($this->qres,$this->link);
return $obj;
}
function nextrow() {
$row=mysql_fetch_row($this->qres,$this->link);
return $row;
}
function showlink() {
echo "Link: $this->link<br>";
}
function showresult() {
echo "Result: $this->qres<br>";
}
}
$db = new mydb;
$db2 = new mydb;
$db->query("select * from portscans");
$db2->query("select * from resources");
while($myobj=$db->nextobj()) {
echo "here's the $myobj->recID record ip address: $myobj->ip<br>";
if($myobj2=$db2->nextobj()) {
echo "News title: $myobj2->name <br>";
}
}
?>