Re: [PHP] Re: Cannot create statement handler

2008-11-17 Thread Thodoris Goltsios





Thodoris wrote:

I was wondering if anyone sees something I am bypassing:

I have this sample code that works in another server:

query($sql);
   // die(var_dump($sthr));
   $res = $sthr->fetch(PDO::FETCH_ASSOC);

   return $res['Name'];

}

try {
   $dbh = new PDO('mysql:host=localhost;port=3306;dbname=ins', 
'root', '', array(PDO::ATTR_PERSISTENT => false));


   $sql = "SELECT * FROM Contracts";
   $sth = $dbh->query($sql);

   print "";

   while($res = $sth->fetch(PDO::FETCH_ASSOC)) {
   $name = getClientFullName($dbh,$res['ClientId']);
   print $name."";
   }
} catch (Exception $e) {
   print $e->getMessage();
}
?>

but in my case I can't make it work on my own server. I have removed 
both PHP and apache and compiled everything for source just to make 
sure that I will avoid possible problems using rpm. It seems that if 
I dump $sthr it returns false.


Although if I print the query and use it directly it works fine.

Apache 2.2.10
PHP 5.2.6
Linux EL5

I've posted this some days ago but none had any idea about this. Do 
think this could be a bug?




obvious but:
do a phpinfo() and check PDO is installed on the failing server
check db is on the failing server
check mysql is running on the failing server
check username and pass are correct for db
check username and pass combo can access via localhost




Yes all that are true because I am able to run a i simple query and 
retrieve the data normally. Not to mention that I double checked this. 
But  when passing  the database handler into a function  then I get 
the results I mentioned before:


Call to a member function fetch() on a non-object



Nonetheless it is a good tip since someone can fail look in to the 
obvious.




At last I have found what the problem was. It was more of a mysql 
configuration problem than PHP. I needed to activate MySQL's buffered 
queries that I was not aware that defaults to non-active in my 
configuration.


I saw a relative bug that suggested this so the only thing that I should 
do was:


$dbh = new PDO('mysql:host=localhost;port=3306;dbname=xxx', 'xxx', 
'xxx', array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY=>true));


So I probably got stuck to the *obvious*.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php rpm

2009-02-04 Thread Thodoris Goltsios

Daniel Brown wrote:

On Wed, Feb 4, 2009 at 09:46,   wrote:
  

Okay here is my question.
Does anyone know of an RPM of php that is pre-compiled with all the extras like 
soap, mssql, freetds, etc...



Afternoon, Rich, et al;

On an RHEL 5.3 system, you should already have 'yum' installed
with the repos ready to go by default, so just drop to a command line
and, as root, type:

yum install php-soap
yum install php-mssql
yum install php-pdo

 etc.

If your 'yum' isn't working from the get-go, check
http://rpmfind.net/ or http://pbone.net/ for the individual RPM's.

  


This probably more then one rpm :-) .

You can do most of things using your distro's repos but usually PHP 
doesn't come in a single rpm. The truth is IMHO that pre-compiled 
packages are responsible for some failures in certain circumstances but 
generally are very good if you don't want to get your hands dirty.


A good way to see how is your distro giving you a prepackaged PHP set of 
rpms is using yum:


# yum search php

This is to get the list of all the available packages. You can then go 
and install what you need. Using:

# yum install php (and whatever you need)

It is not a good practice making an rpm with all the features included 
because it could become huge and it will probably need many dependencies 
in order to get installed properly.


IMHO that is why the best OS to use as on a web server is FreeBSD  
because of the flexibility provided by the ports system and the way that 
PHP is divided into small parts that can be added or removed easily.


Not to mention that you are compiling PHP (as a port) and you can update 
it or remove it like a package the same time.


Again this is my point of view that I wanted to share.

---
Thodoris


Re: [PHP] fileinfo on RHEL5

2009-05-13 Thread Thodoris Goltsios



Thodoris wrote:


Is fileinfo pecl extension installed as a package or with pecl? In 
case it is installed as an rpm try to remove it and install it as an 
extension in case the package is broken for some reason.


I installed it with PECL:

/usr/share/pear/bin/pecl install fileinfo

Other question: where does PECL install this? It's not under 
/usr/share/pear AFAIK. This is the same as with the dev box, so I 
don't think it's an issue; I'm just curious.


Pear and pecl are different. Pear is used to install pure PHP-coded 
extensions that you can include in your projects. You can use this piece 
of code that pear provides by just copying it somewhere and including it 
though not recommended IMHO. Pecl on the other hand provides  C-coded 
extensions that you need to compile and may provide for eg APIs for 
known libraries that must exist in your system.


That is what pecl command does downloads, compiles and installs the 
extension.


A wild guess is that your modules probably live under the 
/usr/lib/php/modules directory or in a directory under the /usr/lib/php.




Anyway, as I said, phpinfo() tells me it's installed & enabled.


Have in mind that you will need the magic_open library for this to work.


You mean libmagic? I have file-4.17-15.el5_3.1, which provides 
libmagic, installed. Strangely, for Fedora, it comes in the file-libs 
package. But I know that, for the dev box, I had to install file-devel 
to get this all working. Neither of these appear to be available for 
RHEL, which I'm discovering is a bit "interesting" to deal with, 
package-wise.


The file package also provides /usr/share/file/magic*, which I have. 
I'd created a link to /etc/magic.mime but decided in the end to just 
pass the correct path to finfo().





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strtotime problem

2008-10-10 Thread Thodoris Goltsios



Greetings, Thodoris.
In reply to Your message dated Wednesday, October 8, 2008, 16:35:40,


  


Greetings to you too :-) .

From your function name I assume you want to use it in MySQL. In that
case, why don't you have MySQL do all the magic for you?
eg. INSERT INTO table (col) VALUES (FROM_UNIXTIME($timestamp));
(using FROM_UNIXTIME($timestamp) will give you the date-time in "mysql 
format" (-MM-DD HH:MM:SS) or any other format (if given via the 
2nd parameter)


  


  


Well actually the basic question was if there is about how to change the 
user input rather then how to retrieve the data.


As for the retrieved data: Those functions belong to framework and by 
changing just a function I can retrieve whatever format I need by 
changing a function instead of changing all the queries in the project.


So I guess I will stick with that although I am aware of the date-time 
functions that mysql has available.



Well I have made these two functions to solve this:



  

function dateMysqlToWeb($mysqldate){



  

$format = 'd/m/Y';
$timestamp = strtotime($mysqldate);



  

return date($format,$timestamp);



  

}



Use SQL DATE_FORMAT instead.
Remember: Request the data you need, not the data stored.

  


BTW it was a good suggestion but that is not always true.


function dateWebToMysql($webdate){

   
  

$format = 'Y-m-d';
$date_part = explode("/",$webdate);
$timestamp = mktime(0,0,0,$date_part[1],$date_part[0],$date_part[2]);



  

return date($format,$timestamp);



  

}



  
My basic problem was how to make the user input from a form into a 
timestamp not how to use it with mysql. Since the format used here is 
dd/mm/ I can't use the strtotime directly bacause as far as I know 
from the documentation I don't think that it changes with the timezone 
(as Stut suggested). So since strtotime understands all these variations 
like:



  

mm/dd/, m/d/yy, mm/d/yy etc



Very basic solution: use 3 editboxes and short javascript sample to confirm
input.
Like
[__]/[__]/[]
...
And fill 'timeconfirm' in onchange/onkeypress event, using verbal format like
Tue, Jan 03, 2008

That way, user actually see which date s/he have entered and you may use it
straightforward.
  


This is possible since strtotime accepts many formats and if one of them 
was dd/mm/ it would work like charm.


Nevertheless I made a javascript to chose the date directly from a 
window by just clicking it. In addition to that I will have to validate 
the form data before the insert no matter what javascript does.
  
I can't use this flexible behavior to get the input if it is not in the 
American format (and correct me if I am wrong). If I explode I will have 
to use the fixed format dd/mm/ and I can't use other input formats 
beside this so I lose this flexible approach.



  

It does work for me now but I was wondering if there was a way to avoid
this.



Not as I know. So, you should either force user to use specific format
(military -MM-DD HH:MM:SS for example) or leave user no chance to enter
wrong data.


  


I am already doing that but it would much more convenient if the format 
we usually use here (dd/mm/) was acceptable depending on the 
timezone as Stut suggested somewhere in this thread.