Wednesday, July 29, 2009
Zend Framework is a pain
and its freaking hard.
dude theres something more simpler. and its called CodeIgniter. ok
done
Wednesday, May 6, 2009
CodeIgniter and SQL Server 2005 using COM class
anyway
i can connect codeigniter and sql server 2005
but it still use com class
its not as a library but as a new db driver and its still the same with mssql driver but we connect to sql server 2005 using com class rather than using php like mssql_whatever function
please read the post that i made in codeigniter forum
Monday, April 13, 2009
PHP and SQL SERVER 2005 with ADODB.CONNECTION
and i think im gonna try this function to.
i found this article from a mailing list here
and im gonna copy paste it to my blog.
thanks for the hardwork AJ.
Ok, here is enough code to get you started :-)
/** This class houses the static methods to creating connections to SQLServer. */ class ADODB {
function ConnectToSQLServer ( $server, $database, $username, $password ) { $obj=new COM('ADODB.connection'); if(!$obj->pinned()) { $obj->open("Provider=SQLOLEDB.1;Server=$server;Database= $database;UID=$username;PWD=$password;"); } register_shutdown_function('_adodb_shutdown'); return $obj; }
function ExecuteQuery($sql,&$connection) { $recordsAffected=0; return $connection->Execute($sql, $recordsAffected, 8); }
function Execute($sql,&$connection) { $ra=0; $connection->Execute($sql,$ra,129); }
}
/* Some util functions */
function dbEscape($s) { return "'".str_replace("'", "''", $s)."'"; }
function forceNumber($number) { if(!is_numeric($number)) { // Trigger error is one of my fuctions, you'd have to do somethine else ;-) //trigger_error("Non numeric passed to forceNumber: '$number'", E_USER_ERROR); } return $number*1.0; // ensures it is stored in php as a number }
/* Some examples of using it. * Please note that in these examples I connect to the DB in each function, * this is totally and utterly wrong for a real situation, you should only * make a connection once per php client connection. */
/* Gets a single result */ function exmpl1() { $server=ADODB::ConnectToSQLServer ( $server, $database, $username, $password ); $recset=0; $recset=ADODB::ExecuteQuery("SELECT MIN(RowID) FROM T_RowID", $server); $ret=$recset->Fields; $ret=$ret->item(0); $ret=$ret->Value; $recset->close(); return $ret; }
/* Gets an array of results */ function exmpl2($Name,$FromId) { $server=ADODB::ConnectToSQLServer ( $server, $database, $username, $password ); $recset=0; $Name=dbEscape($name); $FromId=forceNumber($parent); $recset=ADODB::ExecuteQuery("SELECT ToId FROM T_References WHERE KeyName=$Name AND FromId=$FromId",$server); $ret=array(); while(!$recset->EOF()) { $p=$recset->Fields; $p=$p->item(0); array_push($ret,$p->Value); $recset->movenext(); } $recset->close(); return $ret; }
/* Runs an update only */ function exmpl3($parent,$name,$child) { $server=ADODB::ConnectToSQLServer ( $server, $database, $username, $password ); $parent=forceNumber($parent); $name=substr($name,0,112); $name=dbEscape($name); $child=forceNumber($child); $sql="INSERT INTO T_References (FromId,KeyName,ToId) VALUES ($parent,$name,$server)"; ADODB::Execute($sql,$this->connection); } ?>
Cheers
AJ
....again thanks AJtesting beta test
function index()
{
/* grab the division list */
if ($divisions = $this->main->get_all_divisions())
$data['divisions'][$value['id']=0] = '';
{
foreach ($divisions as $key=>$value)
$data['divisions'][$value['id']] = $value['name'];
}
$data['site_title'] = $this->config->item('site_title');
$data['title'] = "Main Page";
$this->template->write_view('content', 'default/pages/main_index', $data);
$this->template->render();
}
function names()
{
/* set the POST variable */
$division = $this->input->post('division', TRUE);
/* grab the division details */
$item = $this->main->get_division($division);
/* set the output */
$output = ($item !== FALSE) ? $item : '';
echo $output;
}
PHP and SQL SERVER 2005
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.
Tuesday, February 24, 2009
Generating PDF from PHP
this is nice stuff...
you can add picture too..
get it Here http://www.phpclasses.org/browse/package/421.html
Generating MS Word from PHP
that is using class MsDoc....
this class contains a preety much simple function...i think
if you dont know how to apply this class....relax there is a sample how to use this class
this class is provided by http://www.phpclasses.org/
get the class here http://www.phpclasses.org/browse/package/2631.html
Thursday, February 19, 2009
Paging using PHP and MSSQL SERVER 2005 with Code Igniter
some dude from code igniter forum create a simple function to make pagination....
i think this function will work great with all database. and you dont havta use code igniter framework.
im currently using php and mssql server 2005 with Code Igniter Framework
and it works well with the function...
just view it here
code igniter forums
and this is the query that i used :
function get_list($offset){
$sql = "
select top (20) from (
select id,name, ROW_NUMBER() over (order by id) as Result_Number from tm_person) innerSel Where Result_Number >(($offset - 1) *20) Order by Result_Number
)
";
$results = $this->db->query($sql);
return $results->result_array();
}
$offset is number of page values you want to display
and dont forget the paging function read it here code igniter forums
Wednesday, February 4, 2009
PHP Basic
this site contain the very base about web scripting and other kind of script....
i learn all basic about PHP from this site.
its really simple and easy.
even kids can read it too.....perhaps.
Saturday, January 31, 2009
PHP 5 and MSSQL SERVER 2005
they use different server.
one for web server and the other one is for Database Server.
if you anyone of you want to know how to set this i dont know how because im only a programmer.
this project is stupid. i cant stand being a programmer now.
i want to become what i really want.
and what i want is becoming free.
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...
-
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...
-
Read the first Part :: Contain the database and basic creating / generating models / crud CJUIDIALOG In these part 2 I will concentra...
-
im currently doing project using PHP 5 and MSSQL SERVER 2005. they use different server. one for web server and the other one is for Databas...