it seems that the connection was unstable....
im using mssql_pconnect to connect PHP to SQL SERVER 2005.
anyway now im trying a new way to connect PHP and SQL SERVER 2005
and thats using ADODB Connection Object.
to use this you have to call COM class from PHP
function adodb_query($sql){
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$conn->Open("Provider=SQLOLEDB; Data Source=".$this->ado_data_source.";
Initial Catalog=".$this->ado_db_name."; User ID=".$this->ado_db_uid."; Password=".$this->ado_db_pwd."");
$rs = $conn->Execute($sql);
$num_columns = $rs->Fields->Count();
$ado_field_name = array();
for ($i=0; $i < $num_columns; $i++) {
$ado_field_name[] = $rs->Fields($i)->Name;
}
$result = array();
$test = array();
$rowcount = 0;
$rs->MoveFirst;
while (!$rs->EOF) {
for ($i=0; $i < $num_columns; $i++) {
$result[$rowcount][$ado_field_name[$i]] = $rs->Fields[$i]->value;
}
$rs->MoveNext();
$rowcount++;
}
$rs->Close();
$conn->Close();
$conn = null;
return $result;
}
this function will execute query and return it as an array.
it was the same with mssql_fetch_array().
but this has a huge problem.
because of everytime you call the function its create a new connection.
its just mean a longer time to wait.
Subscribe to:
Post Comments (Atom)
Starting to Learn Wordpress
I'm gonna start learning wordpress again. I know it's been a while and I'm using Blogger to write everything. I don't know...
-
Read the first Part :: Contain the database and basic creating / generating models / crud CJUIDIALOG In these part 2 I will concentra...
-
Well if you don’t know what is Yii Framework. I recommend just go to the main site http://www.yiiframework.com And then http://www.yiiframe...
-
if you're new to programming or new to PHP then you should learn from this site, www.w3school.com . this site contain the very base abou...
No comments:
Post a Comment